I’m trying to call up the 10 most popular post_ids entered in a table called postmeta.
There is also a separate table called posts, and it contains post titles, post content and ids.
what I want to do is first figure out which post_ids have the most postmeta entries, and then also query the ‘posts’ table and match the post_ids to post names. I want to output the post name related to the 10 most popular ids, followed by a count of the entries. Ex:
apples(152)
bears(80)
pie(31)
oranges(12)
I’m a bit new to PHP and can’t figure out how to query both of these tables to get what I want.
So far I have this to get the count:
global $wpdb;
$popularity = "
select post_id, count(post_id) as cnt
from $wpdb->postmeta
group by post_id
order by cnt desc
limit 10";
};
You didn’t give enough information on the separate table, so I’m assuming the column names in that table are
titleandid.