Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139863

How to sorting post by rating count in wordpress using dropdown?

$
0
0

Here is my code

<div class="col-sm-3" class="drop">

            <?php if ( is_archive() ) { ?> 

            <select name="sort-review" id="sortbox" onchange="document.location.href='?'+this.options[this.selectedIndex].value;"> 

            <?php } else { ?>

                <select name="sort-review" id="sortbox" onchange="document.location.href='?s=<?php the_search_query(); ?>&rev=<?php echo $_GET['cat']; ?>&'+this.options[this.selectedIndex].value;">
            <?php } ?>
            <option value="">Sort By</option>
            <option value="orderby=title&order=asc">Ascending</option>
            <option value="orderby=title&order=dsc">Descending</option>
            <option value="orderby=rating&order=asc">Rating Low to High</option>
            <option value="orderby=rating&order=dsc">Rating High to Low</option>
            <option value="orderby=review-count&order=asc">Reviews Lowest to Highest</option>
            <option value="orderby=review-count&order=dsc">Reviews Highest to Lowest</option>
        </select>

    </div>

Here is my javascript code

<script type="text/javascript">

    <?php if(( $_GET['orderby'] == 'title') && ($_GET['order'] == 'asc' )) {    ?>
    document.getElementById('sortbox').value='orderby=title&order=asc';

    <?php } elseif (( $_GET['orderby'] == 'title') && ($_GET['order'] == 'dsc' )) { ?>
    document.getElementById('sortbox').value='orderby=review-title&order=dsc';

    <?php } elseif (( $_GET['orderby'] == 'rating') && ($_GET['order'] == 'dsc' )) { ?>
    document.getElementById('sortbox').value='orderby=rating&order=dsc';

    <?php } elseif (( $_GET['orderby'] == 'rating') && ($_GET['order'] == 'asc' )) { ?>
    document.getElementById('sortbox').value='orderby=rating&order=asc';

    <?php } elseif (( $_GET['orderby'] == 'review-count') && ($_GET['order'] == 'asc' )) { ?>
    document.getElementById('sortbox').value='orderby=review-count&order=asc';

    <?php } elseif (( $_GET['orderby'] == 'review-count') && ($_GET['order'] == 'dsc' )) { ?>
    document.getElementById('sortbox').value='orderby=review-count&order=dsc';

    <?php } else { ?>
    document.getElementById('sortbox').value='orderby=title&order=asc';
    <?php } ?>

</script>

With this code Ascending and descending is working perfectly but the rating and review sorting doesn't work properly.


Viewing all articles
Browse latest Browse all 139863

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>