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
- Assign CPT archive page attributes
- Set a hard-coded page-template (post-type-archive) as home/front-page of my wordpress blog?
- Custom taxonomy or custom page templates?
- Dynamically insert an article at the top of a taxonomy archive – or?
- Archiving custom post content?
- archive as a page, so that it can be added in the wp_menu_nav
- Can anyone clarify difference between archive-{posttype}.php, type-{posttype} and date.php?
- How to integrate single and archive templates for custom post type in any WordPress theme
- How do I add custom HTML to the content of an archive page’s posts?
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- Archive links for custom post types
- Show All Custom Post Types On A Single Archive Page
- Use the custom post type archive for taxonomies?
- Custom post type permalink uses archive page to display posts
- How to rewrite custom taxonomy term archive to use THE SAME SLUG/front as CPT
- Custom Post Type setup
- Archive Page for Multiple Custom Post Types
- Taxonomy template page not working
- Can’t access private custom posttype single- or archives-page
- Display Date & Author Info on Custom Post Type Archive Page
- How to constrain the results to a specific post_type on tag archive page?
- Get the link of the first post of a custom taxonomy in a custom taxonomy list
- CPT with its own category and tag url
- How can I relate custom post types?
- 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
- How to know which archive page is active
- Need to have an archive widget which organizes and displays a custom post type using a custom date field
- Archive page for custom post type and custom taxonomy
- Archive Template being used instead of Category Template for Custom Post Type
- Why does my URL keep returning 404 error code?
- pre_get_posts works in post type archive but not in single post
- Menu’s breaking, now showing all page links on site
- Display CPT index page as front/home page
- How to prevent a custom post type from using the archive.php template?
- Event Archive by Month
- How do I override the default number of items to be listed on an archive.php page? [duplicate]
- How to have multiple archive pages?
- Create a Custom Path to Archive
- Advanced archive url structure (category, tag and date)
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- Best way for a plugin to define a custom post type archive template?
- 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?
- Listing authors and date archive from custom post type
- WordPress sitemap with Custom Post Types
- users post count
- Archive page of CPT’s custom Taxonomy
- Display all Categories except ones with a specific parent
- How to achieve a multi-taxomony layout with posts?
- Pagination links for custom post type shows correct number of links, but links result in Page not found
- Archive per year of a custom post getting the wrong post
- Creating archive like functionality through birectional relationships
- Custom Post Type Archive Page showing as 404
- Finding the CPT archive template source
- Custom Post type page content (archive page)
- Set up Custom Taxonomy Archive Template File To Cover 3 Categories
- Group custom post type posts by month
- ACF Pro Accessing fields on a Custom Post Type
- Custom WordPress theme not displaying posts from category
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- How to show custom post count in archive page
- Do not show child pages within a file page
- Custom post types not showing on the standard WordPress Category page
- Tell wordpress to show a single page instead of an archive page
- Archive for custom taxonomy
- Custom Post Type archive page listing a 404 or single post
- Turning archive templates to a page template maintaining the slug
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Custom post type categories giving 404
- Order archive custom posts by taxonomy term [duplicate]
- Custom post type pagination problem – page 1 and 2 show same content
- Adding Custom Post Types to category/tag/author archives breaks header content
- Custom category taxonomy – archive page not showing up
- Custom Archive – hide posts until a search is made?
- 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
- How can i remove post type archive URL?
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- get first limited words from a custom post in the archive page
- Custom taxonomy archive slug overwrites static page
- I broke it! Custom post type archive gets redirected to home
- Iterating over custom post type archive returns incorrect first ID
- Want to display my custom date archive to date.php but dont know how
- Show index and not the archive for “Dog Custom Post” with default slug
- How can I generate a list of post-type specific categories?
- 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”