• Hi experts,

    I am new to WordPress, I got a site which is using the “I love it!” theme. It provides a like function and record number of likes.

    I am trying to sort all the posts by the number of likes, but I just don’t know how to do it. I have tried plugins as well, but the meta key of each post in that theme are being stored in a different table “postmeta”.

    query = new WP_Query( array ( 'orderby' => 'meta_value_num', 'meta_key' => 'nr_like' ) );

    I can’t find the loop in the theme, I have made up the query script, I don’t know where should I put it into to make it work.

    Could anyone help me or just advice me, pretty confused actually?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter A7bert

    (@a7bert)

    Looks like it doesn’t support display the number of likes in the post list.

    Thread Starter A7bert

    (@a7bert)

    Anyone can help me?

    Hey A7bert. I just went through a very intensive query based project.

    I had to set up an events posting section, where each post had a start and end date and then I had to query all posts that fell within the correct timeframe.

    Take a look at tax_query:

    $args = array(
       'meta_key' => 'nr_like',
       'order' => 'ASC',
       'meta_query' => array(
           array(
               'key' => 'nr_like'
           )
       ),
       'orderby' => 'meta_value_num'
     );
     $query = new WP_Query($args);

    Evan

    Thread Starter A7bert

    (@a7bert)

    Oh no, sorry for my late reply, I thought nobody was looking at this anymore.

    Thank you so much, Evan, your query is exactly what I need, but my theme is just so strange… I have written the query, but I really don’t know where to put, I don’t understand its loop.

    Also, I found the number of likes is stored in the postmeta’s meta_key column. Is it possible to create some sql script to make the value of the meta key as the post’s custom field?

    I know I have asked a bit much and complicated. Thanks in advance, I will update this post with the result.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to sort posts by post meta in WordPress’ is closed to new replies.