Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Sort posts by number of likes #39

Open
piotrkulpinski opened this issue Dec 19, 2016 · 1 comment
Open

Sort posts by number of likes #39

piotrkulpinski opened this issue Dec 19, 2016 · 1 comment

Comments

@piotrkulpinski
Copy link

piotrkulpinski commented Dec 19, 2016

Hi guys,
I was wondering if you know any way to sort posts by the number of likes they have?
I know I can do that using 'orderby' => 'meta_value_num' but then it won't include the results that don't have the post meta value in the database.

Thanks!

@rjmccollam
Copy link

I just integrated this with a site I did and needed to output the 3 most liked posts. I combed through the code a little and they are actually adding a meta value that can be queried.

Here is how I did it and it worked:

$args = array(
	'post_type' => 'post',
	'posts_per_page' => 3,
	'orderby'   => 'meta_value_num',
	'meta_key'  => '_user_liked',
);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants