How to query all posts using "meta_key" and "orderby"?

Hi, I followed this tutorial to start counting post views in Frontity.
The request in every post view is working fine, however I’m kinda lost as how to return the top 4 most-read posts.
The tutorial final step says “Now it’s easy to make a query for the most popular posts by including ‘meta_key’ => ‘views’ and ‘orderby’ => ‘meta_value_num’ as query arguments.”

But I don’t know how to do this.

I need to retrieve the 4 most popular posts so I can list them in the homepage. It would be good too if I could get only recent (2 weeks ago to current day) posts, to achieve kind of a “trending new posts” effect.

I tried searching the docs but maybe I’m searching for the wrong terms.

I’m not sure if this is a complete answer, but maybe it’ll help somewhat. I tried to query posts from my testing environment, using the meta-keys as well. I ended up with a request url like this:[orderby]=_portfolio_url&order=desc

So I guess your url could look something like this:

But maybe you already fabricated something like this as well and are just unsure on how to use the returned posts in Frontity. That I wouldn’t know as well (yet).


Yes, this is really some work to do that is not directly Frontity related but more WordPress related. One of the challenges of working with Frontity is being able of getting the info we need of WordPress via REST API.

Besides the one you mention

Here you have some resources that may be helpful for this:

Hope this helps