Ctreate a query from a single category slug

Ctreate a query from a 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:

Tags: ✓
Autor: Dimitar Radev | Modified: September 20, 2018 at 9:53 pm | Category: Functions  •  WordPress


Leave a Reply

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

Advertising

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 …