This should do the trick:
add_action( 'pre_get_posts', 'add_tours_post_type_to_query' );
function add_tours_post_type_to_query( $query ) {
if ( is_home() && $query->is_main_query() ){
$query->set( 'post_type', array( 'tours' ) );
$query->set( 'posts_per_page', 1 );
}
return $query;
}
For the future the Codex can be your friend. Exactly this is explained there.
Related Posts:
- Notice: Undefined index: suppress_filters
- show all custom posts types in home page
- Shortcode to return single custom post based on post taxonomy
- How to divide Subcategories into pages of parent category wordpress
- Check that a slug is present in the get_terms request
- Is there a way to use ‘publicly_queryable’ => false only on specific taxonomy term?
- Code in custom widget queries all posts, when it should only query the current post
- How come Featured Image isn’t showing up in my Custom Post Type?
- How to use a custom post type archive as front page?
- Get the ID of the latest post
- Set posts of a custom post type to be private by default?
- Sort custom post type list table by display name of a user id stored as post meta value
- clients list using wordpress
- Date archives for custom post type
- How can I add dropdown widget/box to admin post page?
- Query posts between two dates (custom meta keys) CMB2
- Adding posts of custom type into the main feed
- Custom Select Query with Custom Post Types
- Append taxonomy terms as class names in markup?
- Display only custom post type count for current author on the “At a Glance” dashboard widget
- adding .current* tags to custom post types and taxonomies
- Calculating Bayesian average for custom post type
- How to filter custom taxonomy categories on archive?
- GravityForm: Populate Dropdown with custom post type [closed]
- How to debug a blank page?
- query posts and custom post type with meta key
- WordPress Orderby Numeric Value Not Working
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Query string parameters from custom fields, inconsistent results
- WooCommerce product search titles only
- Custom Taxonomy Permalinks Redirection
- Add custom column in custom post type edit page
- Order By Post Type ThenBy Taxonomy
- Custom query to filter posts that have current post as a taxonomy [closed]
- custom post type not showing in menu
- How to modify archive query with pre_get_posts to append CPTs?
- convert custom query to wp_query
- Get parse_query filter to return slug instead of id
- Change CPT archive title
- I need to add endpoint for wordpress categories
- Featured image overlay when changing post status
- Query taxonomy of taxonomy of custom post type
- Hide a widget inside a div on specific type of post
- Custom Post Type within the Loop on Homepage (Page Template)
- First custom field value (out of several) displayed twice after query
- Displaying Posts from Custom Post Types
- How to organise this data within WordPress
- Global custom meta box
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- How to query 2 custom post types that need to share a slug?
- PHP question: how to combine syntax?
- custom post for slider
- WP_Query() with custom post type and taxonomy — get all terms?
- Navigate posts with different post type that are in the same categories
- Listing custom post types on archive page with array
- Show Custom Message in WordPress Admin
- How to conditionally add Custom Post Type to Front Page
- How exclude or skip post type with get_next_post_link
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- Query not work for current taxonomy
- Create short URL with auto 301 redirect
- Display a post from custom post type only if all the selected taxonomies and custom field value matches the record
- Is it possible to use array_walk() to append terms to an array of posts?
- WordPress notification if new post published
- Custom Post Type setup
- new WP_query > displays posts only once instead of running through full array
- Pagination on search results page
- Twitter Product Cards
- Custom meta box in custom post type not working
- All in one calendar custom post type query doesnt work as expected
- Function to add custom HTML into head in custom post-type list page
- Submit Custom Postypes from frontend
- Need help with Custom Post Types and Taxonomies
- Conflict in function to allow single post template based on category
- Query filter by value in meta_value array
- How to add specific terms in a custom post type?
- Limit custom post type to the authors only on front-end!
- Meta query and compare “!=” not working as expected
- Create posts inside CPT post
- How to hide sub fields in a field group and also the entire field group if the answer selected is “no”
- Send mail to author when custom post type is saved
- Recovering data about custom post and taxonomy types
- is using “require_once” in wordpress theme affect the speed ???
- Custom permalink rewrite rules – how do I fix this?
- Populate custom post type/custom fields from an external database
- Work and Display a Custom Post Type as a normal Post
- Custom Field to post_title
- Post Custom & Taxonomy 404 error
- How To Display Category list from Portfolio post type plugin?
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- Modify shortcode to work with custom taxonomies and slugs
- Calling the first & last post by category in custom post type
- Query child posts on parents single.php?
- WordPress can only query up to 766
- Allow authors to create article image
- Allow admin to determine the order of queries?
- How to add post type in masonry posts elementory widget
- Comments are not working on Custom Post Type
- I want to show a list of post with title that have link goes to that post and icon under the specific category to which it belongs