From the course: WordPress: Custom Post Types and Taxonomies

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Creating a custom loop for post types

Creating a custom loop for post types - WordPress Tutorial

From the course: WordPress: Custom Post Types and Taxonomies

Start my 1-month free trial

Creating a custom loop for post types

- [Instructor] Custom post types aren't just for creating other types of posts. They can also be used to include different content throughout the page. With our businesses, we wanted to display an index of businesses in a directory style, but we've also created an events type, which we can include on other templates to show users what's happening in the area. This requires a custom loop, which we'll create here. Let's go to our Code Editor, and open up the functions.php file. At the end of the file, we're going to create a new function called lil_show_events(). Here, we'll want to create a new posts query, calling WP_Query, and that requires an array of arguments. Let's set this up first. We'll create an array called $args, and then we'll send it a number of key value pairs. The first, is going to be post_type. This is going to tell WP_Query, which post types to return. So, we're going to set that to event, and then we're also going to put a limit on the number of events that are…

Contents