Jeffrey Nerona
Jeffrey Nerona

Reputation: 135

Wordpress sort by value from specific table

I'm trying to get 4 posts in order by 'pageviews' from a plugin named Wordpress Popular posts. I found in phpmyadmin where it stores the page views per post. My problem is that the values for 'pageviews' for the post is not in the wp_postmeta but in a separate table: wp_popularpostdata and named pageviews. Please help :)

phpmyadmin

from wp_popularpostdata

postid | pageviews

..1..............14

the code below I'm trying returns nothing

$args = array(
        'posts_per_page' => 4,
        'meta_key' => pageviews,
        'orderby' => meta_value_num,
        'order' => DESC,
    );
                $my_query = new WP_Query($args);

Upvotes: 1

Views: 208

Answers (1)

Felipe Elia
Felipe Elia

Reputation: 1418

You could use the built-in function wpp_get_mostpopular as explained here:

if (function_exists('wpp_get_mostpopular'))
    wpp_get_mostpopular("range=weekly&order_by=comments");

If it isn't sufficient to you, you'll have to alter the query through wordpress filters like posts_join, posts_where and etc. The docs should help you to find the way.

Upvotes: 1

Related Questions