Countdown to Pinegrow 3.0

– Read more about The All New Drag & Drop & The Improved Library Panel

  • Features
  • Documentation
  • Forum
  • Blog
  • Download
Back

Create a Loop with a Custom Post Type

Categories: WordPress

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.

CPT_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!

The following screenshot is from our PGWP-Landy template which is freely available and ready to undergo all your tests and experiments 🙂

Sources:
https://codex.wordpress.org/Class_Reference/WP_Query



Last updated on October 1, 2015 at 7:00 pm


Print this article

Find this document useful ? Share it !
  • Helpdesk

    • What Pinegrow is and isn’t
    • Support Forum
    • #Slack Community
    • Release notes
    • Download older versions
    • Contact Us
Back to Top
  • Recent Articles

    • How to Try Pinegrow for free for 7 days ?
    • Use the right jQuery version in your WordPress themes projects with Bootstrap V3.3.x
    • Countdown to Pinegrow 3.0 – A New Feature Presented Every Week
    • Experience Feedback: The relaunch of Mr. Bürli
    • How to use ACF Pro Flexible Content with Pinegrow WP
  • Editing

    • Layout
    • Elements
    • Text
    • Code
    • Javascript
    • PHP, ASP, ERB
    • Editing with Atom Editor
    • Tips & Tricks
    • More …
  • Pro Features

    • Features Overview
    • Projects
    • Master Pages
    • Components
    • Editable areas
    • Libraries
    • Partials
    • CMS
  • Blocks

    • Components
    • Editable areas
    • Build your own Blocks
    • Bootstrap Blocks
    • Bootstrap Blocks for WP
  • Helpdesk

    • What Pinegrow is and isn’t
    • Support Forum
    • #Slack Community
    • Release notes
    • Download older versions
    • Contact Us
Pinegrow Web Editor © Humane technologies LLC, Poklukarjeva 22, 1000 Ljubljana, Slovenia