The post_class
function will do this for you automatically within the loop:
<div <?php post_class(); ?>>
which will add some combination of these classes:
- .post-[id]
- .[post-type]
- .type-[post-type]
- .status-[post-status]
- .format-[post-format] (default to ‘standard’)
- .post-password-required
- .post-password-protected
- .has-post-thumbnail
- .sticky
- .hentry (hAtom microformat pages)
- .[taxonomy]-[taxonomy-slug] (includes category)
- .tag-[tag-name]
You can also get just the post type within the loop via the get_post_type
function:
<?php echo get_post_type(); ?>
Related Posts:
- Prevent pre_get_posts filter on specific post type
- Search multiple custom fields by using meta_query
- Custom Taxonomy with Custom Post Type Finds No Posts
- Impossible to get Attachments Outside WordPress?
- WP_Query custom post type query not showing the exact post type
- How does order=asc effect a wp_query (its acting pretty weird in a loop)
- Display custom post type for specific user
- Related “custom post type” using “custom taxonomy”
- Is there a (preferable built-in) way to check what custom queries are used in a theme?
- Custom Form / Search with Custom Post Type Data
- How can I fetch all the dates from custom fields from various different custom post types and show / list them at one place in ascending order?
- Multiple WordPress Sites, Same Database but Filtered Content
- WP_Query for CPT with filter by another WP_Query
- Sort CPT by taxonomy AND THEN by custom field
- How to use a custom post type archive as front page?
- Combining queries with different arguments per post type
- How to make a WP_Query search with custom post types?
- $wp_query->queried_object->ID throws warning: Undefined property
- The Operator “NOT IN” Does Not Work In tax_query
- Display Custom Post Type Fields
- Admin Post Update Redirection to Posts Screen
- Get posts with tag all post types
- How to get the parent’s taxonomy?
- Single Page WordPress CSS and JS links
- WordPress query by multiple Custom fields and order by date
- Help with hierarchical custom taxonomies and permalinks…almost there
- New WP_query in template not working with CPT+category on some pages
- Disable dragging of metaboxes in custom post types?
- Displaying a specific post in a wp query by post id
- How to delete all posts from a custom post type?
- Structure for projects and clients
- Query custom post types and a specific page?
- Optimised Code for Pulling Taxonomy Posts
- Why is my custom loop not filtering correctly nor paginating?
- Custom post types with custom directories
- Saving repeated option values in a custom query
- How can I get the first 50% of all posts (within a custom post type)?
- Fetch taxonomies by custom post type id array
- is there a way to retrieve posts that do not have a featured image assigned?
- Related posts in all categories of current post (custom post types)
- Why does querying on post_tags (which has been applied to custom post types) only return posts?
- Group posts by custom post type
- shortcode to show custom post types by category
- Genesis filterable portfolio isotope [closed]
- Plugin: register custom post types, child ready and performance best practices
- convert custom query to wp_query
- Loop to fetch 3 post_thumbnail instances from 3 most recent custom post types named “portfolio”
- Custom post ui plugin & WP_Query – Polylang
- How to use load more custom post type data normal or according to on click category tab In WP
- wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query
- How to add attributes to taxonomies that may be different from post to post?
- How to sort posts in a custom post type by title in ascending order by default?
- custom post type vs. conditionally displaying meta boxes for specific terms?
- Edit the_content() function so to add a div wrapper
- How to make WP_Query not to show irrelevant posts?
- Number of posts in the archive
- Replace dynamically content in a custom database table when a custom post is created
- WP_query – Filter by tax_query and meta_query using multiple select
- Create a list of recent Custom Post Types posts
- Custom post type menu
- Empty search input does not return all posts
- How to sort a WP_Query by a custom field AND ALSO filter by a different custom field
- Get current user id
- List latest post out of 2 custom post types
- How to properly use Categories with Custom Post Types
- Displaying Portfolio Filter by Category Order (alphabetically)
- What is the best way to manage small blocks of content on my home page?
- One post auto attached to many another items
- Custom Post Type Query W/Category Dropdown
- Auto update publish date of CPT Post if default post custom field value match to cpt post CF Value
- Pin posts to top of custom loop
- WP_Query – How To Query Only Custom Posts With No Children of Their Own?
- Foreach result into WP_query
- Query custom post type and custom field by URL parameters
- wp delete duplicate entries of custom post types every 15 minutes
- Custom Taxonomy – fields
- CPT Loop, include taxonomies and disclude others?
- Query posts based on user preferences
- CPT post doesnt shows tags and category on backend admin page
- Adding a nav menu for a custom post type
- How to use costum database table for custom post type
- connect users to Custom post types
- Custom Pagination based on Custom Post Type
- Custom user roles
- Querying, storing, and using data from 2 separate custom post types
- date_query won’t accept day parameter, but will accept month and year for a custom post
- Registering an optional custom post type from a plugin
- WordPress custom post type
- Custom Post ‘Post Per Page’ Crashing Page?
- Custom metabox value not saving
- Issue with permalinks for custom post type
- Paged within a custom content type template [duplicate]
- Custom Post Query Combined with Conditional Tags
- Custom loop won’t work, can’t find problem
- Query by post type or category
- How to exclude certain portfolios from a loop
- Advise on Custom Taxonomies and Structure
- show the most recent date of all posts to display on front end
- Delete old thumbnail when updating new
- Dynamically count the number of custom post types associated to a custom taxonomy