admin管理员组

文章数量:1287774

I'm rather new to Wordpress development, and i have been making my own code to count and display views count on posts. Now, what i'm trying to do is get the homepage to sort these posts in descending order, ordered by view count.

Is there anyway to replace the query that fetches the posts list with this kind of query ?

SELECT posts.*, meta.meta_value FROM wp_posts AS posts 
INNER JOIN wp_postmeta AS meta
ON posts.ID = meta.post_id 
WHERE posts.post_type = 'post' AND posts.post_status = 'publish' AND meta.meta_key = 'post_views_count'
ORDER BY meta.meta_value DESC;

I have been trying to look at the query object in the documentation but i'll admit it's been a struggle to get this to work.

If anyone would be so kind to explain to me how to get there, so i can learn a bit more about this, if you have the time to spare, of course.

Thanks in advance.

本文标签: querySorting my posts on homepage my specific value in postmeta table