$request['post_type']
should contain the requested post type for any custom type. The default post
type will have a name
, but no post_type
. Pages will have pagename
and no post_type
.
EDIT- determining custom post type based on taxonomy set in request:
function cpt_request_filters( $request ){
if( ! is_admin() ){
global $wp_taxonomies;
foreach( $request as $tax_key => $value ){
if( array_key_exists( $tax_key, $wp_taxonomies ) ){
return cpt_parse_taxonomy_string( $request, $wp_taxonomies[$tax_key]->object_type[0], $tax_key );
}
}
}
return $request;
}
add_filter( 'request', 'cpt_request_filters' );
Related Posts:
- Enforcing canonical URLs with multiple custom post types
- WordPress request fiter order by related post’s post_title
- How to query 2 custom post types that need to share a slug?
- Safe to throw 404 error in request filter?
- Custom endpoint filtering post by custom taxonomies
- Create category only for custom post type
- Reducing the use of global $post
- custom post type or taxonomy
- How to create a mini directory in WordPress?
- Admin to user notices – best practices?
- Removing CPT slug from URL results in 404 error for archive page
- Internationalize / translate custom post types & taxonomies
- Anyway to assign custom post types to a specific category?
- Search Post Title Only [duplicate]
- Custom post type’s slug gets wrong when adding a custom meta box
- Can’t sort order of wp_query with 2 meta keys
- How to get source of custom meta image?
- Custom Post Type archive giving 404
- Get count of custom post type created by current user
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- How can I show recent posts from same taxonomy as the post currently being viewed?
- How could I create a ‘private comments’ section on a custom post type?
- Custom post type capabilities require “create_posts” to access the edit posts list page
- If post_type is This or This
- Group custom posts by custom taxonomy names
- Using GraphQL Plugin with Pods Framework
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Custom Post Type with Templates using Meta Boxes?
- Copy post from category to custum post type
- Wrong request query on cpt and tax
- Using default WP menu functionality to link to custom post-type listing?
- Permalink for a custom post type isn’t working and I don’t know why
- Custom post type not showing in search result
- Listing posts under primary and secondary taxonomies
- Custom post type, organized by categories
- Removing Custom Permalink Structure for Custom Post Type
- How to import files to individual posts of a custom type
- What content types are shown at a search page?
- Set template for custom post type?
- How do I display a list showing custom post types nested within a taxonomy?
- Display posts with tag for custom post type only
- get_post_types – exclude multiple post types by name
- Custom post type loop with custom category filtering
- Check if user has comment on current post
- Assigning a category to a custom post type in WordPress
- Showing taxonomy terms on custom post type
- Create a page by importing data from an XML file ( On clicking a button inside admin options page)
- get_terms() returns Trying to get property of non-object error for custom taxonomy
- Get admin area editor in frontend
- If meta_value of meta_key is less than today’s date update meta key
- How to list custom post types on a custom post type page?
- Custom post type title of each author in his own post
- Permalink Trouble with custom post types
- Shortcode in pages or tempate files for custom post type
- “Author” custom post type
- How to show the post which checkbox is not selected
- Copy data from 2 different ACF custom post types with relation
- Display custom post type taxonomy in a WordPress excerpt for current post
- How can I write slugs / permalinks as: custom post type -> custom taxonomy and custom post type -> custom taxonomy (one CPT and many taxo)?
- Orderby if between two meta fields
- How can I use a custom template to load custom post type posts based on a post_meta value
- Displaying Custom Fields from Custom Post Types [closed]
- Register post type getting error 404
- Change Custom Post Type to Post + Category
- Which File Populating CPTs in Slug URL
- Add tags to a “pending” post before publishing
- Fixed custom fields depending on posttype/category
- Running get_posts within get_posts to get children of children
- Templates list in “Page Attributes” metabox is inaccurate
- creating different edit screens for different roles
- wordpress form processing to custom post type not working
- Custom Post Type as invoice or order template
- Pagination in custom loop for custom post type throwing 404 error
- Make each Value of custom field show related posts when clicked
- How can you preserve URLs when moving posts to a custom post type?
- Two post types with same single template
- How to create an upload page (front side)
- Tracking Total Pageviews By Post Type In Google Analytics
- Why custom search engine only searches in post titles of custom posts?
- Send email on creation of custom post type and use get_post_meta()
- Can I add a wordpress page using the slug for a CPT rewrite
- YARRP related posts with custom post type and wp-graphql
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Is there a function that replace category name with a icon?
- Custom Post Type urls not working
- Just the First Metabox what saves the data!
- pre_get_posts causes Custom Posts appear under ‘Pages’ menu
- Assign a tag to custom post type using a query
- Why isn’t page attributes dropdown not showing up in a custom post type
- Show custom category archive as front page and remove taxonomy slug from urls
- Post object GUID adding http:/
- WordPress does not show the custom fields box
- Create a hierarchical list of posts that’s grouped and nested by category
- Two pagination in one page without AJAX
- I want to show a list of post with title that have link goes to that post and icon under the specific category to which it belongs
- Show a wordpress custom post condtionally using a category term
- Categorizing Custom Posts in Bulk Based on Title
- Query order by a numeric ACF field
- Meta_query question
- post__in select all custom posts and not the selected array of ids