Create a query from a single category slug

Generate WordPress wuery based on single category slug

The function below creates a WP_Query object and takes two variables. $cat – category slug and $per_page – how much posts should be displayed per page.

To use it simply to rewrite the $wp_query in that template as shown below.

This will give you the option to use all features just as a normal page however if you need to save the initial query data for later use, assign it to a different variable before overwriting $wp_query.

Like so:

Now you can use the initial query as shown below:

Autor: Dimitar Radev | Modified: April 22, 2019 at 9:31 pm

Leave a Reply

Your email address will not be published. Required fields are marked *


Related posts

Featured Image Alt Text

Limited Number of Tags after Posts in your Custom WordPress Theme

Snippet: How to limit the number of displayed tags in your post template? If you want to limit the number of tags you …