I am working on a Wordpress theme that has a homepage slider. I have a table in Wordpress database that stores post view counts and I would like to make my slider show the top viewed posts.
This is the SQL to get the top post, Post ID's
SELECT `post_id`, `single_views`
FROM `wp_ak_popularity`
ORDER BY `single_views`
DESC LIMIT 30
And below is my current Wordpress DB query that is currently in use.
$featured = new WP_Query(
array(
'no_found_rows' => TRUE,
'update_post_meta_cache' => FALSE,
'update_post_term_cache' => FALSE,
'ignore_sticky_posts' => 1,
'posts_per_page' => wpb_option('featured-slider-number'),
'cat' => wpb_option('featured-slider-category')
)
);
I was looking at the WordPress documentation site and saw that I could use something like this to only query the posts that I need...
$featured = new WP_Query(
array(
post_type' => 'post',
'post__in' => array( 2, 5, 12, 14, 20 )
)
);
Where I need help is how I can make the first Database query and get those results into a variable like this
$post_ids = '2, 5, 12, 14, 20';
So I can then make the main Database query by simply passing in the Post ID's that I need.
Can someone show me how to get the first list of ID's?