WordPress: Custom Loop Query
Creating a custom loop query can allow you to utilize the base WordPress loop with your own custom query. This could be used in many situations such as pulling only posts with a specific tag or pulling your own custom post types for displaying in a shortcode.
To utilize this you should have a basic knowledge of the WordPress loop.
First set up the arguments variable with the desired perimeters. For this example were going to request any post with the tag ‘cooking’.
Now create a variable to hold your new results using the WP_Query class. Were going to pass are new arguments through the WP_Query’s first perimeter.
From here we can use the WordPress loop as we normally would to cycle through the returned records. A full example can be found below.
More information on WP_Query including query perimeters can be found on the WordPress codex here.
Recent Comments