There are a several of ways to do this. Put:
var_dump($wp_query->query,get_queried_object()); die;
In your archive.php
and you should see two of those ways.
$wp_query->query
will have post_type
component for custom post types. That will not be there for post
post types. get_queried_object
will return quite a bit of data for custom post types but null for post
post type.
There are also some related template tags that might help. is_post_type_archive
comes to mind.
Between those you should have the information you need to put together whatever logic you need. It is not clear from you question what the end result is supposed to be, so I can’t really write much.
Since you specifically named archive.php
that is what I tested in. You may need different code for some other template, especially with get_queried_object
which returns very different information depending on the context.
Related Posts:
- WordPress custom post type archive with description
- CPT: archive-cpt.php VS custom page template
- Why is my site using index.php instead of archive?
- Custom post type archive page blank
- Is possible register two archive pages for single custom post type?
- How to display custom post types AND regular posts separately on a shared taxonomy archive?
- how to pass args for archive.php query?
- WordPress CPT archive page display sticky post first and then display the rest of the posts in same Query
- Adding content to archive and taxonomy pages on custom post types?
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- $query->set in pre_get_posts is unintentionally affecting the backend
- Pagination throws 404 error on custom taxonomy archive pages
- Proper way of making custom post type landing page or archive page
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Custom Post Type Archives with 0 Posts Redirects as 404
- Archive page with multiple taxonomies rewrite
- Archive page…limiting posts per page
- WP 3.1 – archive pages for custom content types possible now without a plugin?
- Date archives for custom post type
- Custom Post Type Archive URL takes over page URL
- Custom comment status possible?
- How to Add Pages Under Custom Post Type URL Structure?
- paginate function in archive for custom-post-type
- Include Custom Posts Type in Year/Month/Date Archive
- where can I see my custom post type archive template?
- Call different archive page based on post type
- How to create archive page for taxonomy terms within custom post type
- Custom Post Types and archives
- Display CPT description on archive.php pages for all CPT
- How to get “custom post type”-archive with working permalink to it?
- Custom template page with custom archives listing by user
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- Custom Post Type Archive Page Filtering
- Root slug of taxonomy returning 404
- How to modify archive query with pre_get_posts to append CPTs?
- Custom post type is showing custom home page, not archive page
- URL of a custom post type’s post format archive?
- Isotope Filtering with Bootstrap Tabs – Custom Post Type Query Loop in each Tab (Have to click twice to filter)
- Change CPT archive title
- The loop seems stuck to a single (now deleted) post
- Use “archive” as slug for custom post type
- Is it better to use filter for the_content in archive pages?
- How can I get this request to use the Custom Post Type page template instead?
- Custom post type posts don’t show in archive widget
- Archive for a Taxonomy of a Custom Post type
- Custom Post Archive is not working
- Problems with 404, .htaccess, permalinks and WordPress custom posts locally on Snow Leopard
- What’s the name of the custom post type yearly archive template?
- How can I use archive-{post_type}.php theme template?
- Taxonomy archive 404ing (not term archive)
- Return the name of the post type
- Custom taxonomy or custom page templates?
- archive as a page, so that it can be added in the wp_menu_nav
- How do I add custom HTML to the content of an archive page’s posts?
- Use the custom post type archive for taxonomies?
- Custom Post Type setup
- Taxonomy template page not working
- CPT with its own category and tag url
- Custom Post Type Archive template not being called
- Can’t replace the default sidebar with a custom sidebar on Custom Post Type in Genesis
- Dynamic category name in query post
- Custom Post Type Archive Pagination
- Need to have an archive widget which organizes and displays a custom post type using a custom date field
- Archive Template being used instead of Category Template for Custom Post Type
- pre_get_posts works in post type archive but not in single post
- Menu’s breaking, now showing all page links on site
- How can I allow users to edit text that will be displayed on a custom post type archive page?
- How can I increase the post count for custom post types only?
- How can I tell if I’m on a custom post type archive page?
- users post count
- Custom Post Type Archive Page showing as 404
- Custom Post Type archive page listing a 404 or single post
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Custom post type pagination problem – page 1 and 2 show same content
- The page or ad listing you are trying to reach no longer exists or has expired
- One of my headings is mysteriously coming up as a link in my CPT Archive
- get first limited words from a custom post in the archive page
- I broke it! Custom post type archive gets redirected to home
- Show index and not the archive for “Dog Custom Post” with default slug
- Custom post type archive page not showing on archive-posttype.php
- Custom post type with two templates
- Custom Post Type tag taxonomy “Page Not Found”
- Making a archive gallery page for a custom post type which already has an archive page
- Custom nav menu current item custom link problem
- Stop Custom post type from being searched via URL
- archive-{custom_post_type}.php not getting recognized wordpress
- Archive.php is not displaying tags
- Archive templates based on taxonomies
- Organizing Custom Post Type Archive Template
- Custom post type category page not working
- Custom Post Types Archives and daily/monthly joke
- Categories in custom post types
- listing custom post type category page
- Display results from two Custom Post Types in page template
- Two different archive pages showing the same content
- How to make a list of posts displaying them 5 by 5 with a “next posts” link?
- Query Custom Post Type and sort by year
- Custom post types not using archive structure
- How to turn custom-post archive into an overview page, listing the metadata of the posts?
- Pagination not working for archive