Well, looks like you’ve almost got it. To include multiple custom post types in the WP_Query
object, just change:
$query->set( 'post_type', array( 'recipes' ) );
to:
$query->set( 'post_type', array( 'recipes', 'another-custom-post-type' ) );
Basically adding more elements to the array.
So the final code becomes:
function blestrecipes_cpt_filter( $query ) {
if ( ! is_admin() && $query->is_main_query() && is_home() ) {
$query->set( 'post_type', array( 'recipes', 'another-custom-post-type' ) );
}
}
add_action( 'pre_get_posts', 'blestrecipes_cpt_filter' );
Related Posts:
- Call to a member function add_rewrite_tag() on null
- How to add custom taxonomy slug in CPT permalink?
- WordPress: Displaying all the post tags from within a specific taxonomy’s term
- Relationship between custom post type and page/single templates
- Display a query with multiple post types and same relationship on a single page
- Display all categories (with link) of custom post type – WordPress
- How can I get values from a custom post type depending on where I click on my SVG map?
- Displaying custom meta box value in a custom post page
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- WordPress different custom tag being displayed in on tag list
- How to enable REST API on custom post type without Gutenberg?
- Can I associate a custom post type with another custom post type?
- Get category name of current post (CPT UI)
- How to sort custom sortable column by custom table value
- I want to show image from custom field image on my custom page template
- How to disable page create for custom post type, but allow a page with the post types slug to be created?
- How to make multiple custom taxonomies sit under custom post type slug?
- Limit a search box by CPT + taxonomies, in only one page
- WordPress taxonomy and terms question
- Load style and script for custom post type metabox
- Custom CPT – Programmatically create categories to assign CPT when a new one is created
- Why do I get a 404 error on my custom post type archive pagination?
- How do I exclude the current post from the upcoming post query
- Save_Post change Custom Post Type Post title to post id number
- Custom Filtering date with newsletter
- Ajax infinite scroll random order shows duplicate posts on custom post type
- How exactly do automatic updates work?
- What is in media-template.php, and how does it work?
- Inconsistent temporary 404s on whole install | PHP error with post-template.php
- Is it possible to disable a function of a parent theme?
- Create Image Uploader for Widget
- WordPress Ajax always returns a 404 error
- Displaying a variable stored in functions.php inside widget
- Custom Meta Field – Youtube embed
- How can I add dropdown widget/box to admin post page?
- How to get all existing post types
- phpMyAdmin displays error when importing database
- Setting up 2 SMTP accounts: 1 for wordpress and 1 for woocommerce
- Function set default image when image not present
- Received nothing after executing AJAX post function
- Displaying the last post on static homepage
- Using foreach loop breaks
- Add child pages of parent to navbar PHP
- WordPress plugin for nicer looking slugs? Have multiple pages named the same but they get different slugs
- Showing a different gallery in a seperate post
- How to put “Read more” link in Custom Excerpt inside p tag?
- $wpdb->update with multiple parameters gives error
- WordPress Shortcodes.. printf is outputting a random number… Can’t figure out WHY?
- Remove metabox from WordPress menu editor page?
- Improve page speed loading using CDN and async or defer attribute
- Categorize custom post type
- Get users that likes the post
- wordpress visual composer change grid builder post link
- My php header() function is not working [closed]
- PHP array to JS array to use in google map
- meaning of (array)function()
- deactivating an active plugin using if page
- Can a page contain php code?
- Last class on last headline?
- How to relocate paypal button gateway on checkout page in woocommerce
- Passing the name of selected color from the custom component to `render_callback`
- your php installation be missing the MySQL extension WordPress CPANEL [closed]
- WordPress mod_rewrite not working on php fpm
- Notice: Trying to get property of non-object
- How do I pull information from one wordpress backend into another? [closed]
- Adding data to custom wordpress database table
- Change Spaces to Dashes?
- How to add videos on my home page slider?
- select a single val though a table in wordpress
- How can I enter on the Thank you page in woocommerce the discount code I assigned to the product category?
- PHP inside echo HTML
- Filter ‘comment_notification_text’ not working
- How do I check if a product is in two categories?
- oceanwp+woo mobile cart sidebar text
- Check if current post in loop is last on current page
- php code for outputting a custom page in my account
- wordpress contact form messages not sending although it saying they were sent successfully with this php code
- Find out div class
- Add a top bar to a wordpress theme without editing the header.php file?
- Using a PHP form, get the page title or any other element in the sent e-mail
- Custom field in PHP file
- How do I fix Undefined variable using $_POST in function?
- Check the database for a postmeta field
- Random code snippet showing up in browser
- Help hooking into user_register
- Same Server, Same PHP, One Site Doesn’t Work [closed]
- Featured Products not showing up in “Featured” area of homepage
- How can I include tags in wordpress search without a plugin
- Retrieve $_POST data to send to javascript without using localize script
- Search bar for page that searches only particular page IDs
- Auto remove empty values in array
- if conditional in sidebar plugin Password content shortcode
- PHP Call outside class function inside anonymous function
- Excerpt all post content Content Same Size without word cutting off
- add if statement to the featured image
- Upgrade WordPress core programmatically with PHP?
- How to pass and validate nonce in custom REST routes
- how to display custom taxonomies in front page
- How to get a database field value from a WordPress table? [closed]
- Woocommerce – Include custom user meta in order ‘filter by registered customer’ Ajax search