On Likebtn-plugin homepage ([https://likebtn.com/en/wordpress-like-button-plugin#sort_posts_by_likes][1]) they give this code to input in a template file, e.g. index.php, archives.php, page.php, such that the posts are sorted based on the number of likes. I have input the code in the archives.php and the content is sorted correctly when I click on a category. But I also want to use the function in my pages so I tried to enter the code in my page-tmpl.php file but it does not seem to be working. Everything in the page just disappears. What am I doing wrong?

The page-tmpl.php file looks like this with the Likebtn-code incerted at the top:

$args  = array(
    'orderby' => 'meta_value',
    'order' => 'DESC',
    'meta_query' => array(
        'relation' => 'OR',
            'key' => 'Likes',
            'compare' => 'NOT EXISTS',
            'type' => 'numeric'
            'key' => 'Likes',
            'compare' => 'EXISTS',
            'type' => 'numeric'
$args = array_merge( $args , $wp_query->query );
<?php if ( hu_is_checked( 'singular-page-featured-image' ) ) { hu_get_template_part('parts/page-image'); } ?>

<div class="entry themeform">
  <?php the_content(); ?>
  <nav class="pagination group">
      //Checks for and uses wp_pagenavi to display page navigation for multi-page posts.
      if ( function_exists('wp_pagenavi') )
        wp_pagenavi( array( 'type' => 'multipart' ) );
        wp_link_pages(array('before'=>'<div class="post-pages">'.__('Pages:','hueman'),'after'=>'</div>'));
  <div class="clear"></div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.