You can just grab the first post from the main query and see which post type it is:
if ( have_posts() ) {
$post_type = $wp_query->posts[0]->post_type;
}
If you run this code directly in a main template file you should be fine, but if it’s in a function you will need to call global $wp_query;
first.
Related Posts:
- How to manage a dynamic multi-level page hierearchy system?
- Custom Post Type used for FAQs Accordion
- show only one category posts in admin
- How to change permalink structure for custom post type and it’s taxonomies?
- Get the first post term
- How to show all posts of the category in wordpress?
- Get category id from post id of a custom post type
- Creating “static” taxonomies to choose from, inside custom post type?
- How can I list all the categories under a Custom Post Type (taxonomy)?
- How to list all categories and tags in a page?
- How can you make permalink work for custom post type and taxonomy?
- How to get a list of term names of the custom post type im currently on in single.php
- Rewrite custom post & taxonomy to share same URL path
- How to show related posts by category or custom post type?
- Structuring a product catalogue in WordPress [closed]
- Display taxonomy term only if there’s a value
- List all custom post type posts from a given category?
- Custom post type taxonomy template
- get_categories for custom post type and filter by custom taxonomy (brand) and list child categories of a defined category
- Category page only displaying the posts from a custom type
- Display types of posts in edit.php instead of All, Published, Scheduled and Draft
- Show Post Count of a Category
- Custom Post Types and Categories?
- Custom Taxonomy – Tags Metabox is showing instead of Categories
- How to create new category for custom post type?
- Get Post Primary Category
- Pagination is not working on single-{slug}.php but works fine on page-{slug}.php
- How to show CPTs in term archive
- Display all posts in main category and 1 subcategory
- Show category ID on custom post type
- Show custom post type filtered by category
- How do I do this with WordPress? Taxonomies?
- Showing posts from different categories and from custom post type
- Categories of custom taxonomy don’t show any posts
- How to display custom taxonomies with links in filter menu?
- Add custom post type settings to wordress default posts
- Get related posts of child term of custom post type
- Limit amount of posts made within a custom taxonomy
- Problem with displaying posts in the CPT category
- Set a checkmark in a category based on a URL-parameter
- Get the category from custom post type
- Custom Post Slug same as Parents Category Slug
- Conditional statement for if archive page has posts which contain certain taxonomies/categories/tags, show those terms
- How can I show 1 featured post in a styled element, and the next few below differently styled
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Redirect to another page using contact form 7? [closed]
- WP the_posts() on single-cars.php get category link
- Categories and tags for custom post types
- Create new custom post and post category of same name
- Custom post types and ‘new WP_Query’
- Variable not working in WP_Query
- How to Display Posts From Category Within a Custom Taxonomy?
- Showing custom post type categories in the menu
- Targeting categories in custom fields
- Invalid Taxonomy
- Need help deciding on a taxonomy
- Stores category posts in an array
- Get Posts by Category, Tag , and CPT Taxonomy
- Get assigned post categories
- Default Category Page not showing custom post type which has taxonomy category
- Restrict category access to specific users/groups. Author always has access
- Post Query not working
- Categories won’t appear on custom post type
- Copy/Move selected taxonomy terms to another taxonomy for posts
- Use post in multiple places on a page with multiple posts
- Custom Post Type with modified permalink structure results in 404
- Am I mixing up the concept of posts pages and categories?
- Building a Data Intensive Website with WordPress
- Custom post type, taxonomy and admin bar
- Displaying taxonomies as category links within sidebar and creating pages for these
- Display all Categories except ones with a specific parent
- What is the best way to set the post category (Custom Post Type) automatically based on the one of the tags assigned to the post?
- Custom post type archive page filters
- How to show related posts of category on post within custom posttype
- Post category behave like a Post in back office menu
- Save data is post using php front end
- Define multiple prefixes for custom post type
- get taxonomies from terms
- Create custom post type categories
- How to show posts of the same category on a page?
- Set a Default CPT taxonomy by taxonomy id
- how to create custom taxonomy drop downs for parents and child
- Custom Post By Category
- Categories manage
- I can not call the categories of custom post type
- Reuse the “category” slug for a custom post type
- Multiple Custom Post Type with different Taxonomies
- How to create groups like that in buddypress?
- Only show current category post
- Filter By Term Not Working – Custom Post Type
- Post Editor: display categories from current post type taxonomy only?
- Best way to structure article and issue relationship for CPT
- Display all post types together
- category_name not working in WP_Query
- How can I set up the URL for a category archive for a custom post type?
- Custom Post Type order Title ASC
- Query multiple post of which one by taxonomy
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Is it possible for post and custom post type to share a category base slug?