The simple answer is “yes, you can”, but I’m pretty sure it won’t satisfy you 😉
So… How can you achieve this and show only custom posts on home.php? All you need is to use pre_get_posts hook like so:
add_action( 'pre_get_posts', 'add_custom_post_types_to_home_query' );
function add_custom_post_types_to_home_query( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'book', 'movie' ) );
return $query;
}
The code above will change the main query so it shows only books and movies.
Related Posts:
- wp_query and comment_parent – select only posts with top level comments
- Want to filter only parent post in admin area
- Setting proper query for multiple custom admin filters
- Genesis filterable portfolio isotope [closed]
- Filtering WP_Query
- creat filter with wp_query
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How can I made custom taxonomies relationship?
- Filter Posts from the Main Query
- conditional filter
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- Filter posts by their related field’s custom field
- How to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- Output all terms slugs for a loop filter
- WP_Query: include custom post type only with specific meta value
- Pagination on a custom post type loop
- showing custom post types of a certain category only
- WP_Query orderby modified to include custom meta changes
- WordPress custom loop filter by meta_key and value with serialize data
- Returning a list of custom post types excluding those without a specific meta_value
- query private custom post type
- Display custom post type from dynamic custom field
- Query/list all terms and their custom post count
- Append date to custom post type url slug
- Linking to the most recent post in a Custom Post Type
- How to make sure content doesn’t display if selection is empty
- Filtering WP_Query Dynamically on the Front-End
- Show one item per category of a custom post type
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Storing posts from query and accessing later via AJAX call
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Query custom post type with tags
- wp_query check if integer exists in custom field’s array
- convert custom query to wp_query
- Wrong request query on cpt and tax
- How can I see a list of my Custom Post Types of the last term I was in?
- Previous/Next Link by Meta Value in CPT
- Show custom post type filtered by category
- Randomize Posts. Skip the first post in ascending order
- Creating a navigation menu of all posts of a custom post type and their children posts?
- Get custom taxonomies from multiple posts
- Pagination for Custom Taxonomy Page [duplicate]
- Search / Filter posts on Title/Content OR Tags
- Pagination on with query_posts in custom post type template
- Wp_query: sort by PHP variable
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- Custom-Posttype & Custom Taxonomy WP_Query
- Crafting WP_Query array, sort by date
- Custom loop with multiple taxonomy queries
- Return one unique custom post type result when it shares a custom taxonomy in WP_QUERY?
- Displaying custom taxonomy in the admin list of a custom post type
- Converting the_content string to an array?
- forming WP_Query for posts of all post types but from specific categories
- How can I run this code once so that my generated post title doesn’t keep changing on publish/update?
- Get latest 3 posts from multiple CPT in one query
- Loop to fetch 3 post_thumbnail instances from 3 most recent custom post types named “portfolio”
- filter custom post type by meta key in dashboard
- Display upcoming Events for next 7 Days
- Categories of custom taxonomy don’t show any posts
- Isotope Filtering with Bootstrap Tabs – Custom Post Type Query Loop in each Tab (Have to click twice to filter)
- Custom post ui plugin & WP_Query – Polylang
- How to add a post slug to a url?
- How can I get the number of custom post type posts that have a specific attachment image set?
- How to use load more custom post type data normal or according to on click category tab In WP
- orderby rand is not working for a custom post types
- WordPress sort search results by custom order
- How to filter wp_list_categories output with some custom post type meta query?
- Problem querying Custom post type by custom fields
- Orderby CPT custom fields not working
- How to Filter custom post type by taxonomy?
- Custom taxonomy rewrite give pagination 404
- WP_Query order by custom field, then randomly order some of results
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Mixing 2 custom post types with posts output in specific pattern
- Custom post taxonomies as tax_query terms?
- Filter term taxonomy metabox in custom post type
- Troubles with acf/save_post and WP_Query
- Query custom post type with ACF Date
- How to do WP_Query with two meta fields with orderby clause
- Stuck in Order by more then one
- Display featured image from one CPT within another CPT query
- Custom WP Query on custom meta and sort by multiple meta keys value
- Show only one post on custom post type archive
- Woocommerce search pagination not working
- How to order WP_Query by parent for hierarchical Custom Post Type?
- Including metaboxes from custom post types in global search — continued
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- Query Multiple Custom Posts by Custom Fields
- What’s the WP way to load remaining custom posts?
- WooCommerce sort products by the actual product width(not the shipping width)
- How to change the post type a theme shows by default?
- Why is this query not working? (Standard posts + custom post type)
- How do you paginate a query grouped by month?
- Custom taxonomies relationship
- filter custom post in rest api with custom function
- Get Posts by multiple custom fields is not working
- Custom post type ‘articles’ ignores posts_per_page, reserved post_type?
- Several post types on WP Query by tag and taxonomy
- WP Query with categories only shows one post and ignores the category