In your code ( $query->is_home() && $query->is_date() && $query->is_main_query() )
always returns false
because $query->is_home()
and $query->is_date()
cannot be true
on same page.
Try this,
function add_custom_post_type_to_query( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_date() || $query->is_home() ) {
$query->set( 'post_type', array('post', 'pictures') );
}
}
}
add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );
I hope this helps!
Related Posts:
- Prevent pre_get_posts filter on specific post type
- $query->set in pre_get_posts is unintentionally affecting the backend
- How to put custom post types on front page
- Add Custom Post Type to Current Query
- How to show more posts on an archive page?
- Include post id[s] into WP_Query()
- Pre get posts for single post
- How to get my Custom Post Type to display in Recent Posts using “pre_get_posts”
- Pre_get_posts Gives 404 on Custom Post Type
- filter search result with custom post type meta key
- Order posts by (hierarchical custom) taxonomy terms and term children
- Meta Query “IN” doesn’t work with ACF checkbox filter
- How Do I Use WP_Query to Run This Database Query as Search Result?
- Limiting number of custom posts shown on taxonomy page
- Include custom post type in “all posts”
- Can’t sort order of wp_query with 2 meta keys
- Sort custom post types by last name in the backend
- Displaying custom post type on category pages but not on blog listings
- Custom post type with tags
- pre get posts changing the query
- Display all Posts and only certain Custom Post Types with meta fields
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Using pre_get_posts to Filter Posts
- Custom search for custom post meta with pre_get_posts interferes with WP search
- Issue with pre_get_posts on custom post type archive pages
- Using pre_get_posts to filter one loop in a multiloop archive
- How to sort custom post type posts in default order by multiple fields?
- pre_get_posts on custom post type
- Change archive page template using pre_get_post
- How to modify archive query with pre_get_posts to append CPTs?
- Advanced or not so advanced pre_get_posts query
- Multiple meta_values in the pre_get_posts filter?
- Showing posts from different categories and from custom post type
- Custom post type search using $_SESSION and pre_get_posts
- How to sort custom columns for custom post type without meta query and pre_get_posts?
- Custom Post Type Archive Error, Takes Last Post as Title and Doesn’t Work
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Query multiple taxonomies with pre get posts
- Main menu not appearing in custom post type archive
- Excluding a Custom Post Type with a specific tag using pre_get_posts
- how to show records that don’t have custom meta value
- CPT is simply not displayed in the main archive with “pre_get_posts”
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- How to query for posts (hierarchical custom post type) that have children but are NOT top level?
- CPT Archive pre_get_posts not working?
- pre_get_posts works in post type archive but not in single post
- How to use pre_get_posts on archive page custom post type
- Order posts by taxonomy terms
- Query to Exclude Child Pages from Custom Post Type Archive
- How do I troubleshoot pre_get_posts with Debug Bar?
- How to hide private posts even if user is admin
- Display Specific Posts at Start of Loop
- List all posts associated under custom taxonomy
- Set different posts_per_page for custom post type/taxonomy
- CPT year wise archive based on custom date Field
- Apply pre_get_posts to specific custom post type in the admin area
- pre_get_posts gives 404 error on Custom Post
- Meta query broken since 4.7.4 Update
- What’s the most efficient way to get two queries based on an if statement?
- Pre_get_posts comparison with custom field doesn’t work
- Custom Post Type shows pagination (w/404) or posts_per_page query, but not both
- Custom Post Search
- pre_get_posts with multiple post types AND a meta_key
- pre_get_posts not firing at all
- Fetch post meta in the same query as the main loop
- Problem to show custom post type in archive page category wise
- Using $seed on a custom post type for randomly displayed posts
- Adding custom post types to the default loop, yet only posts that has terms from the core taxonomies
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- How do I sort post listing by child post count?
- pre_get_posts action doesn’t work
- custom post types, pre_get_posts, wp_list_categories
- pre_get_posts causes Custom Posts appear under ‘Pages’ menu
- Sorting by Title for Post Archive Categories for Custom Post Type
- How can I incldue a “private” post type in a loop for public users?
- WordPress 3.3 custom post type with /%postname%/ permastruct?
- Custom Taxonomy’s Label to change the text appearing in Appearance > Menu
- Have different search results template depending of custom post type searched
- How do I programmatically add items of content to a custom post type?
- Add nonexisting pages to navigation
- How to add plugin custom field to custom post type?
- Multiple post type queries (with specific arguments for each)
- How can you handle rewrite rules for custom post types with option to filter on custom taxonomy terms?
- Query Multiple Meta Values and display only when it has both meta values
- What template files do I need to customise custom-category-term-links rather than fall back on archive.php?
- wp_update_term_count_now doesn’t work with a custom post type?
- Troubles with acf/save_post and WP_Query
- How to specify a template for a path like http://example.com/something?
- Two custom post types divided in two columns inside a bootstrap carousel
- How can I relate custom post types?
- Display author box on just certain category posts?
- How to divide Subcategories into pages of parent category wordpress
- Is there any filter to add a custom attribute to the tag in admin panel?
- Tell wordpress to show a single page instead of an archive page
- Post display in separate page [duplicate]
- Delete Post by User
- Have two (permalinks) urls for a same custom post type
- If taxonomy show class of active
- querying to custom field over ACF REST API
- Fatal Error WordPress Custom Post Type UI + WPML