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 to customize a permalink (URL) structure?
- Get next and previous 3 posts in a term in single post page
- Custom Post Type with Templates using Meta Boxes?
- convert custom query to wp_query
- Custom post type is showing custom home page, not archive page
- Can I list a custom post type within another custom post type in the admin area?
- Change custom post type slug from plugin options
- Making certain categories of CPT not publicly queryable
- Search / Filter posts on Title/Content OR Tags
- Get parse_query filter to return slug instead of id
- Can’t edit custom post type
- Querying both pages and posts
- Meta query for custom post type ignored in main query
- Set URL link to featured image of custom post type
- Change CPT archive title
- AJAX load more for different custom post type loops
- PHP variable not regenerating when publishing multiple posts at the same time
- Querying Two Custom Post Types with OR Not Working
- How do I move/order posts with a tag to the end?
- On update or create post redirect to current post position in list
- I need to add endpoint for wordpress categories
- custom home page and custom index page?
- How to target a specific custom post type post and its all children and grandchildren?
- Featured image overlay when changing post status
- get_post_meta not working on publishing
- creat filter with wp_query
- Redirect 404 page with ID in slug to associated page with same ID in slug
- WordPress wrapped added a span tag to every single p tag
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- Display featured image from one CPT within another CPT query
- Query taxonomy of taxonomy of custom post type
- Best way to style first post differently?
- How to make custom posts types display when published for the future
- How to rewrite url for any specific taxonomy?
- Specific query for custom post type
- create a new page from a custom post type similar to an authors page
- CPT archive admin menu label
- Anon function and add_meta_box
- Hide a widget inside a div on specific type of post
- Shortcode not working with post counter
- Static page determines as home, but it is not
- Display post content with respect to its title?
- Changing default ‘posts’ parameters with register_post_type_args
- Custom Post Type within the Loop on Homepage (Page Template)
- First custom field value (out of several) displayed twice after query
- Prioritize posts in query by meta keys?
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Cannot save CPT meta box
- What’s the equivalent of Hide From Menus on MODX on WordPress?
- Allow users to create posts without logging in?
- How to change permalink to include custom post type
- WP_Query orderby and tax_query
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Displaying Posts from Custom Post Types
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Different Ways to Query Custom Post Types?
- Add term to custom post type on draft
- How to assign classes to all elements?
- next_/previous_post_link() `in_same_category` appears to fail when true
- Want to be able to sign up subscribers as authors
- How to organise this data within WordPress
- Load scripts based on post type
- Different Category system needed for the Custom Post Type
- Custom post type posts don’t show in archive widget
- Global custom meta box
- Template not working for the custom Post type
- Showing specific post in order of array wp_query
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- Meta-Boxes for CustomPostType cause PHP Errors and Notices in “Add New” view
- categories should be available across all custom post types
- Warning: Invalid argument supplied for foreach() in post.php [closed]
- Featured Image field not appearing in Custom post type
- Post-thumbnail only for specific post-types?
- custom post type metaboxes not saving
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Number of posts in the archive
- Query of custom post types only shows first post
- Custom query for custom post_type
- Adding custom field values to wp_list_pages
- Query multiple taxonomies with pre get posts
- Enable taxonomies by post type in an array of CPTs
- How to query 2 custom post types that need to share a slug?
- Is it possible to show multiple (custom) post types at the wp homepage only by using pluging code?
- PHP question: how to combine syntax?
- Loop increase number
- custom post for slider
- ACF in wordpress
- Query Custom Post Types with checkboxes
- Change Slug of a Custom Post Type
- WP_Query() with custom post type and taxonomy — get all terms?
- Excerpt function for any content