As you have already seen in our WordPress video course, adding a loop is the way to display posts in your WordPress theme. But the standard loop only works for standard post types (pages and posts). Custom post types require some specific settings.
IMPORTANT: This tutorial is the continuation of Introduction to Custom Post Types in Pinegrow WP and you should have created a custom post type in your template and added a few posts of that type in the WordPress admin interface before following the instructions below.
In your HTML template, select the element that you want to “loop” and in WP panel, from the Loops section – just like for a standard post type – add The loop
Because you are going to create a custom query, locate the Custom WP Query name property and set a short name without spaces and special characters. Choose a name which is consistent with the identifiers of the custom post type. (For example, if your custom post type name is acme_features, you can use features_query).
Adding a name bring up some (a lot of) new loop properties.
In this short tutorial, we are not going to examine all the query properties and possibilities but just setup a few of them in order to create a simple loop for your custom post type.
First, we set which posts will be part of our loop.
We only want the ones with the status “published” so from the POST & PAGE PARAMETERS section, we leave Post type empty and we set Post status to publish.
We provide the name of the Custom Post Type that we have previously created and that we want to target. So in Custom post types, enter the name of your Custom Post type.
From the PAGINATION PARAMETERS section, you can setup the number of posts per page. This setting is useful if you want to limit the number of posts, for example, because of design constraints.
Then, finally, from the ORDER PARAMETERS section, you can setup the order for your posts display.
You can have a quick look at the PHP code generated by Pinegrow by activating the PHP code preview.
PHP code preview provides a live display of your modifications, so it can be useful and educational to activate it while proceeding to the setup of your custom query.
And that’s it, you can now save your template, export your theme and test it live on your WordPress installation.
Your theme should now display your custom post type!
Last updated on October 1, 2015 at 7:00 pm