Never use new WP_Query
for the main query of an archive template. WordPress has already queried the correct posts and things like pagination are based on that query. If you want to modify that query you should use the pre_get_posts
to modify the main query before it is run.
The hook runs on every query that is performed, and the WP_Query
object is passed a parameter so that you can modify it. You can use its various methods to identify which query you’re modifying.
To modify the main archive of a resource
post type to also display posts your code would look like this:
add_action(
'pre_get_posts',
function( $query ) {
if ( ! is_admin() && $query->is_post_type_archive( 'resource' ) ) {
$query->set( 'post_type', [ 'resource', 'post' ] );
}
}
);
Related Posts:
- Pagination not working with custom loop
- How to use a custom post type as front page?
- pagination not working for category.php (custom post types in categories)
- Custom post type pagination error
- Pagination Not Working When Used With WP_Query() `offset` Property
- Is it possible to add query parameters on the archive page?
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- Pagination not working with custom loop
- Fourth page of custom post type archive page does not exist
- Display CPT posts based on specific taxonomy
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Pagination on a custom post type loop
- WP_Query orderby modified to include custom meta changes
- Am unable to reset a query properly
- How to make sure content doesn’t display if selection is empty
- Show one item per category of a custom post type
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- How to display all posts from standard posts to custom post types in a loop with pagination?
- Get next and previous 3 posts in a term in single post page
- convert custom query to wp_query
- Previous/Next Link by Meta Value in CPT
- Pagination for Custom Taxonomy Page [duplicate]
- Search / Filter posts on Title/Content OR Tags
- Pagination on with query_posts in custom post type template
- Custom loop with multiple taxonomy queries
- Paging doesn’t work?
- How do I move/order posts with a tag to the end?
- Custom taxonomy rewrite give pagination 404
- creat filter with wp_query
- Woocommerce search pagination not working
- What’s the WP way to load remaining custom posts?
- How do you paginate a query grouped by month?
- WP Query with categories only shows one post and ignores the category
- Pagination issue on category.php using custom post type query
- Problem: wp_query outputs all images on site
- First custom field value (out of several) displayed twice after query
- Prioritize posts in query by meta keys?
- WP_Query orderby and tax_query
- Custom Theme With Custom Loops
- Custom Post Types strange pagination problem
- Different Ways to Query Custom Post Types?
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- can these 3 queries be re-written as 1 query?
- Showing specific post in order of array wp_query
- Wrapping x posts in html without leaving empty html
- WP Query post__in not returning correct results
- Sort posts in loop by the WooCommerce Membership of the author
- Number of posts in the archive
- How can I group posts by months and years?
- Pagination Error : Duplicate argument being outputted
- Multiple Custom Post Type queries, how to DRY it up
- Custon Content within WordPress Loop
- Loop increase number
- Custom WP_Query always respond with 200 status even when no entry
- Using wp_query to modify the loop in index.php for a CPT
- Custom WP_Query doesn’t display all posts
- WP_Query() with custom post type and taxonomy — get all terms?
- Query & the_content() is showing in the header
- Pagination doesn’t function properly for archive of a custom post type set as the front page
- Trouble with pagination
- Pagination 404 on Index with custom query
- Listing custom post types on archive page with array
- get_pagination not working on a custom post type query (using WP_Query)
- WP_Query with custom post type ID
- How to conditionally add Custom Post Type to Front Page
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Pagination not working on custom query on a page
- Returning a custom content types with meta values
- display posts of custom post type with custom taxonomy
- Break up posts per page in two sections
- Custom Post Type not showing in main loop
- Custom post type and custom taxonomy 404 on page 2
- Trying to add a class to post links
- Pagination on search results page
- postsperpage value not being applied
- Pagination for search results of custom post type [duplicate]
- Display the current post in browser as the first post in a loop (for a slideshow)
- Create query for both custom post type and category
- Custom Post Type Archive Pagination
- Display post from custom post type
- List all Custom Post Type posts excluding certain Taxnomy term
- foreach loop inside the loop creating duplicates in output
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- I am officially missing something about transient posts
- All blog posts are not showing up
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Query custom posts from custom taxonomy
- Custom Post type showing up in loop, regular posts are not showing up
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Single parent post lists child posts with pagination
- How do I list a custom field and custom taxonomies for each result in a loop?
- Custom Post Type Query W/Category Dropdown
- Changing WordPress sort order for returned child pages
- Custom Post Type, Pagination and 404s?
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?