From the course: WordPress: Custom Post Types and Taxonomies
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Custom post types on the front page - WordPress Tutorial
From the course: WordPress: Custom Post Types and Taxonomies
Custom post types on the front page
- [Instructor] By default, the main query that's powering WordPress's front page will only return posts of the post type. Here, we're going to add our businesses to the front page as well. So let's go ahead and open up our code editor, and then open up our child themes functions.php file. We'll start by adding an action. So we'll add a couple of lines to functions.php, and then we'll add the action 'pre_get_posts'. What this action does is say right before you send the main query off to get posts, call this function, which will likely modify the query. So we'll call this 'lil_add_business_to_query', and then we'll create that function. For consistency's sake, we'll create the function above the add_action. So let's go ahead and copy that function we just created, and then we'll write function, we'll paste the name, and this function, unlike the other ones we've used so far, actually accepts an argument, and that argument is query. WordPress is passing the query to this action for…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.