As I already mentioned in my comments, you must use pre_get_posts
to add custom post types to archive pages.
One thing you must keep in mind here though, you have two archive pages here, archive.php and archive-event.php, so is_archive()
is going to return true on both, which will alter both pages. You will need to exclude archive-event.php from your function. To do this, you’ll need to make use of is_post_type_archive()
to check and exclude that specific page
For all the possible parameters you can use with pre_get_posts
, go have a look at WP_Query
function cpt_in_archive($query) {
if ( !is_admin() && $query->is_main_query() && $query->is_archive() && $query->!is_post_type_archive( 'event' )) {
$query->set( 'post_type', array( 'post', 'event' ) );
$query->set( 'orderby', 'date' );
}
}
add_action( 'pre_get_posts' , 'cpt_in_archive' );
Related Posts:
- Wp-query causing problems with the_content();
- How to create posts (not post template) to be displayed on projects page?
- Quickest way to get last or oldest post date – WP Query
- How do I create an archive page for standard posts?
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Loop on front-page.php
- WP_Query is printing out only one post when posts_per_page is set to multiple
- WordPress Orderby Numeric Value Not Working
- is there a way to retrieve posts that do not have a featured image assigned?
- How to add post_type=value when editing that post type in the WordPress admin?
- Storing posts from query and accessing later via AJAX call
- Show custom post type filtered by category
- Get latest 3 posts from multiple CPT in one query
- Several post types on WP Query by tag and taxonomy
- Prioritize posts in query by meta keys?
- How to get all tags of a custom post type by id
- WP the_posts() on single-cars.php get category link
- Different Limit number of post on different archive page
- Custom post types and ‘new WP_Query’
- Variable not working in WP_Query
- WP_Query with custom post type ID
- Query within a foreach within a query (queryception)
- wordpress lists similar type of posts in a custom post type
- display posts of custom post type with custom taxonomy
- How to Query in WordPress which shows Alphabetic Posts?
- How to query Posts from a custom post type which contains a custom taxonomy?
- Display post from custom post type
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Display Parent-Child Posts in specific order by comparing IDs in array
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- wp_post_delete is deleting all offices
- SEARCH QUERIES – REVERSE OUTPUT
- How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?
- minimize wp_query call to database
- subtracting the current post form then whole loop, which is generating all CPT titles
- post type => ‘any’ not applied my custom queries
- Custom Post By Category
- Custom post Query and WordPress Post Query Clash
- How to get the posts that my following users are liked?
- Get post from Category by Priority
- Most efficient way of showing children posts?
- Only show current category post
- How To Loop Through list with Custom Post Types
- Calling specific page with wp query
- Retrieving IDs of child pages which are in a different post type
- Query Posts From Multiple Post Types
- Change display wp post type to wp custom post type
- Dynamically change post_parent in every page load?
- Cannot exclude particular post from loop of custom post type
- How do I hide single category post on my post page
- Wp-theme Development
- show the most recent date of all posts to display on front end
- Sort ACF by custom taxonomy
- Get Posts in a Custom Post Type category
- Limit the post for differents custom post type in the same wp_query
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- Multiple Content Block
- Display Custom Post Type in Recent Posts
- Query for posts in 2 taxonomies
- IF statement in a do_shortcode
- Make `previous_post_link()` Function Show The Post After Next i.e. Jump A Post
- Parent / Child formatting in a list of post of a custom post type
- Remove All, Published and Trashed Post Views in Custom Post Type
- showing custom post types of a certain category only
- Custom taxonomies relationship
- WP_Query orderby and tax_query
- Load Next Posts With AJAX not working with custom post type
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Different Ways to Query Custom Post Types?
- Permalink misbehaving in Custom Post Types
- Display Only Certain Category In a Custom Page Template
- find custom post type post by searching its custom field with my string
- Auto post creation
- All blog posts are not showing up
- Custom post-type custom query – show all posts
- redirect after submiting post for review
- i need to have a tab with gategory post
- Custom Post type to Woocommerce Product type
- Auto delete pages/posts without views
- Filter posts by their related field’s custom field
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- How do I get all authors posts of a custom post type outside loop
- Limit posts per page depending on the size of a div?
- sorting in wp query based on custom field value
- Setting up a page to house certain types of posts
- WordPress loop add heading before first of type
- Featured image in custom post is being disabled
- How to set class to “current-page” on the currently viewed single post within a CPT
- Custom Post Type shows pagination (w/404) or posts_per_page query, but not both
- WP_Query for CPT with filter by another WP_Query
- Is it possible to add query parameters on the archive page?
- Query Only Show Text on Posts With Certain Taxonomy Tag
- Storing/querying custom date data
- Custom Post-type not returning the right child_of
- WP Build-In Post selector for CPT
- How to make a template for a specific post of a custom post type?
- Display ACF object field data using Elementor Custom Query
- WordPress custom field sorting, weird behavior: the latest post is at the end