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
- How do you get the count of posts in an archive page?
- Mixing regular and custom post types (with meta_query) on home page
- $wp_query->queried_object->ID throws warning: Undefined property
- how to filter by last name for custom post
- Display Custom Post Type Fields
- Use WP_Query object inside a function
- WP_Query search custom posts meta date fields
- Get posts with tag all post types
- How to get_queried_object on multiple objects?
- Debug output during filter execution doesn’t work
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- query order by date on custom type: wrong order
- Custom Taxonomy breaking pages permalinks
- Query custom post types and a specific page?
- Calculating Bayesian average for custom post type
- Help with CPT template pagination
- Custom query shows custom post types in trash
- Remove duplicated values from a loop
- Fetch taxonomies by custom post type id array
- How to connect two custom post types with nested loops
- Custom Post type and Custom Field WP_Query
- Display multiple custom post types and sort them chronological by one of their fields
- Using DISTINCT in wp_query
- WooCommerce product search titles only
- Related posts in all categories of current post (custom post types)
- How to show CPTs in term archive
- Custom query to filter posts that have current post as a taxonomy [closed]
- Query/list all terms and their custom post count
- Get custom taxonomies from multiple posts
- Pagination on with query_posts in custom post type template
- Categories of custom taxonomy don’t show any posts
- Custom post ui plugin & WP_Query – Polylang
- How to add a post slug to a url?
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Polylang non-default language ignores tags in WP_Query
- Problem: wp_query outputs all images on site
- wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query
- How does order=asc effect a wp_query (its acting pretty weird in a loop)
- Why is my WP_Query outputting my entries twice?
- How to display Related Posts based on number of taxonomy terms matched
- Create new custom post and post category of same name
- WP_query – Filter by tax_query and meta_query using multiple select
- Create a list of recent Custom Post Types posts
- How do I add custom HTML to the content of an archive page’s posts?
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- Empty search input does not return all posts
- Adding Multiple Post Types to Query [duplicate]
- WP Query results showing posts outside of category ID
- tax_query (if the terms are empty)
- How to count other posts not having specific taxonomy terms?
- Group by custom field value (start and end times)
- Running a custom query inside another cpt single and trying to grab a variable
- Get posts by category name
- WP_Meta_Query object with conditionals
- Problem while filtering by ‘category_name’
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- custom filtering admin columns
- Query filter by value in meta_value array
- WP_Query get always custom post_type for first
- Post Click Redirect to Custom URL instead of Single Post Page
- Foreach result into WP_query
- meta query multiple values for the same key
- Custom post types – meta_query: search lesson which starts sooner
- Wp Query sort order from custom MetaBox
- Query posts based on user preferences
- Most efficient way of showing children posts?
- How can I use WP_Query argument ‘Like %..%’?
- Custom post type and custom taxonomies display
- WordPress custom post type
- Sorting on Taxonomy in archive page
- Custom Search Template for Custom Post Types
- Custom post type single display is ommited
- Query child posts on parents single.php?
- WordPress can only query up to 766
- Custom Post Query Combined with Conditional Tags
- Custom loop won’t work, can’t find problem
- Get all custom_post_type posts + blog posts from one category in a single query
- Customising wordpress search and using $_GET[“s”]
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Rewrite a filter as shortcode (or something like that) to use anywhere in CPT
- add_filter > posts_where works partially
- WordPress custom field sorting, weird behavior: the latest post is at the end
- Default WordPress Query for a Specific Custom Post Type URL
- Dynamically count the number of custom post types associated to a custom taxonomy
- Add post id to url instead of WordPress default -2 suffix