WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to Wordpress so please bear with me.

Please check this link

The posts are currently sorted by date. But if you mouse over on Latest Articles you see there are other options for sorting like Most Viewed Most Liked etc.

What I'm trying to do is make Most Liked the default sorting value instead of Latest Articles

I believe this could be done by modifying codes where the wp_query args are setup

The php file which controls the panel has this code -

$args = array('posts_per_page' => $postsperpage);

I've tried modifying it with this -

$args = array('posts_per_page' => $postsperpage, 'orderby' => 'meta_value_num', 'meta_key' => IT_META_TOTAL_LIKES);

But it doesn't solve the purpose!

Can anyone tell me how do I do this?

share|improve this question
Add single quotes around 'IT_META_TOTAL_LIKES'. Assuming that is your meta_key. – josh Nov 8 '13 at 5:46
@josh That's the meta_key, but adding single quotes doesn't make it work! :( – Sam DG Nov 8 '13 at 5:51
did you tried meta_value, only instead of meta_value_num, these are some hacks that works most of the time, also u'll be needing the single quotes around your meta_key name. also you can use $posts_results = new WP_Query($args); echo "<pre>"; print_r($posts_results);echo "</pre>";, to check the query – sven Nov 8 '13 at 6:07
@dot1 tried with meta_value..didn't work. where do I add the $posts_results line? – Sam DG Nov 8 '13 at 6:14
You are querying the posts on your page, using new WP_Query, just store it in a variable and then echo "<pre>"; print_r($variable_name);echo "</pre>"; to check the query and results – sven Nov 8 '13 at 6:17
up vote 0 down vote accepted

the change you require is a modification to your theme, it will take time and you might end up corrupting it if you are not comfortable working with WordPress, instead of that you can make a child theme for it and make whatever change you want inside it.

A replacement and partial solution would be to add a js in your theme, to click on the link as soon as the div is there, it will refresh the posts automatically for you.

 if( jQuery('.home.blog').find('.articles .icon-liked.liked ') != ''){
   jQuery('.home.blog').find('.articles .icon-liked.liked ').click();
   jQuery('.home.blog').find('.articles .sortbar-title').html('MOST LIKED');

Also I did modified your theme.php to include script in page, added

<script type="text/javascript" src="<?php echo THEME_JS_URI; ?>/custom.js"></script>

to function


its merely a solution but its a solution as of now.

share|improve this answer
I think this has messed up the sorting by date option. Latest Articles & Most Liked now gives the same view! Also, new posts do not show up in that panel. – Sam DG Nov 8 '13 at 9:12
for that to be fixed there are lots of changes required...maybe I can fix that later – sven Nov 8 '13 at 9:15
this should be good till a better solution is found :) – Sam DG Nov 8 '13 at 10:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.