As Kaiser mentioned, the post_type
parameter can accept an array of post types. Updating the function to use is_main_query()
to limit the filter to only the “main” query, the code would look like:
add_action( 'pre_get_posts', 'custom_post_author_archive' );
function custom_post_author_archive( $query )
{
if ( is_main_query() && is_author() )
{
set_query_var( 'post_type', array('post','custom_post') );
}
}
Related Posts:
- How to use a custom post type as front page?
- Querying Posts by Taxonomy From Alternate Network Site
- Query by 2 values of a repeater ACF field
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Having trouble with custom date field for CPT query (WordPress)
- WP_Query search posts by custom post type and custom taxonomy
- Calculating Bayesian average for custom post type
- Conditional to modify query results
- Is it possible to create a shortcode that will query a post based on taxonomies?
- Querying Term Posts in Loop
- Use get_post_types to query only custom posts types
- WordPress Orderby Numeric Value Not Working
- convert custom query to wp_query
- Search / Filter posts on Title/Content OR Tags
- creat filter with wp_query
- First custom field value (out of several) displayed twice after query
- Prioritize posts in query by meta keys?
- WP_Query orderby and tax_query
- Different Ways to Query Custom Post Types?
- Showing specific post in order of array wp_query
- WP_Query() with custom post type and taxonomy — get all terms?
- Returning a custom content types with meta values
- Create query for both custom post type and category
- Query custom posts from custom taxonomy
- Is there a (preferable built-in) way to check what custom queries are used in a theme?
- Change search query in wordpress custom post type
- WP Query from two Custom Post type fields as statement
- WP Query: If field X is empty, show posts based on field Y
- How select query is generated in a Custom Post Type?
- WP_Query for custom taxonomies showing posts from non-specified terms?
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- post type => ‘any’ not applied my custom queries
- Linking posts together with Advanced Custom Fields “both ways”
- Get posts of an specific term of a custom taxonomy
- Conditional posts in WP_query for search
- Query Pulling the same post twice
- Is it possible to add query parameters on the archive page?
- Query child posts on parents single.php?
- Query Posts From Multiple Post Types
- WordPress can only query up to 766
- Filter Custom post type by another Custom post type
- Create a list of months based posts
- Load posts via AJAX without draft status
- Meta query with boolean true/false value
- get attachments for all posts of particular post type
- Search multiple custom fields by using meta_query
- category__in not working on custom post type
- Displaying Posts Related to Other Posts by a Taxonomy Term?
- Date query for a custom meta field
- Set default option in dropdown of WP_Query?
- Combine tax_query and meta_query in WP_Query
- Adding a span when custom post type is updated
- Search tags in CPTs
- How to filter by custom post type in taxonomy archive pages
- Custom query form submission pagination
- Paginated Taxonomy Term Archive including one post per term
- Exclude the parent custom post-type posts only
- Woocommerce query specific product from specific category
- tax_query returning all posts instead of selective posts in WP_Query
- wp_query to find posts by year and month
- Including Custom Meta with posts_where query
- Very Slow Page – How to Optimize # of Queries?
- Get latest 3 posts from multiple CPT in one query
- Display upcoming Events for next 7 Days
- How do I move/order posts with a tag to the end?
- Orderby CPT custom fields not working
- Custom WP Query on custom meta and sort by multiple meta keys value
- Woocommerce search pagination not working
- How to order WP_Query by parent for hierarchical Custom Post Type?
- WP_Query custom post type query not showing the exact post type
- Change sort order when using ‘orderby’ => ‘type’
- Add Custom Post Type of specific Custom Taxonomy to regularly blog loop
- How to get specific post meta by title or id
- WP_Query of custom post type sorted by meta_key has unexpected results
- How to query for posts (hierarchical custom post type) that have children but are NOT top level?
- Hide text if query has no posts
- How do I get the index for a custom post?
- Filtering custom posts by custom fields (ACF) [closed]
- Shortcode / WP_Query in post changes context
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Make Next and Previous on single-$posttype.php use the same order as archive-$posttype.php
- Display custom-post type based on the Title matching the current selected value
- Sort custom post column by generated value?
- Displaying all posts by category and showing content on click
- Numeric pagination custom post type
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- WP Query filter search. Result show all posts instead just custom post type
- Display posts of a hierarchical custom post type excluding parent posts
- Why get_posts() returns empty array while I am trying to get posts from some specific taxonomies and work properly with others?
- get_post_meta for Custom Post Type ( CPT )
- How to query posts by meta keys AND under specific category?
- Shortcode display CPT Query only showing 1 post?
- Query stopped working
- How can I base a query off of the current page post type AND a meta value from another custom post type
- Pagination not working with custom loop
- Fallback if statement based on the number filtered from it
- Get images only from a certain post type
- Display ACF object field data using Elementor Custom Query
- Sort ACF by custom taxonomy