Support » Plugin: Like Button Rating ♥ LikeBtn » Sort archive page

  • Resolved YuriV


    Hi all,

    We purchased this plugin after we read in the documentation that it’s possible to sort posts by likes, using this code:

    $query_args  = array(
        'post_type' => 'post',
        'orderby' => 'meta_value',
        'order' => 'DESC',
        'meta_query' => array(
            'relation' => 'OR',
                'key' => 'Likes',
                'compare' => 'NOT EXISTS',
                'type' => 'numeric'
                'key' => 'Likes',
                'compare' => 'EXISTS',
                'type' => 'numeric'
    $loop = new WP_Query($query_args);
    if ($loop->have_posts()):
            <a href="<?php the_permalink(); ?>">
                    <h3><?php echo the_title();?></h3>
                    <p><?php echo the_content(); ?></p>

    The documentation said this code could be placed on for example archive.php. We placed the code there and it does return the posts by likes, but the problem is it returns all posts as a top list, and not only the posts with the specific tag we’re in. When we visit:

    We of course only want to see the content tagged ‘1’. Support returned a short mail containing:

    Tweak WP_Query code - Follow instructions to add tag parameter to WP_Query:

    Unfortunately we can’t make any sense of these instructions. Does anybody know how to tweak the code above to make it return only posts with the same tag?

    Thanks in advance,


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author LikeBtn



    What kind of loop do you have in archive.php?

    If it is have_posts() you need to insert the following before the loop:
    <?php query_posts($query_string . ‘&meta_key=Likes&orderby=meta_value&meta_type=numeric&order=DESC’); ?>

    Read more here:

    Thanks. Problem is solved.

    Just found there is a mayor problem with this. The given codes shows the items in the right order (top voted on top) but items with no votes at all or not visible at all anymore in the archive-page…

    See for example:

    This achive had 3 items but they’re not visible because they didn’t receive any votes… Do you know how to solve this?

    I did some further research on above issue:

    In WordPress we can select the extra field ‘Likes’ and manual add ‘0’ to new posts. Once we’ve done that the post is also visible on the archive pages with top rated content.

    But of course we can’t go through all articles and manually add ‘0’ to the unrated posts. The plugin should do this.

    Hope you can solve this quickly because at this moment all our new posts aren’t visible………….

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sort archive page’ is closed to new replies.