If you’re doing something in the wp_insert_comment
hook, then you should use the 2nd argument, $comment_object
, if you want to know anything about the post the comment was for. $comment_object
is a WP_Comment
object that has a $comment_post_ID
property that has the ID of the post the comments is for. You can use that to determine its post type. The URL structure is completely irrelevant.
function wpse_304105_update_time( $comment_id, $comment_object ) {
$post_id = $comment_object->comment_post_ID;
if ( get_post_type( $post_id ) === 'top-news' ) {
// Update post time.
}
}
add_action( 'wp_insert_comment', 'wpse_304105_update_time', 99, 2 );
Related Posts:
- Change custom post type slug from plugin options
- How to rewrite url for any specific taxonomy?
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- Generate daily archive whenever any post type is added
- Rewrite slug of custom post type to include post-id
- Can I list a custom post type within another custom post type in the admin area?
- Rewrite rules for custom posts types
- Rewrite post type slug only for child theme
- wp_list_categories() – current-cat class also inside posts?
- Custom Post Types, URL rewrite on multiple CPTs
- Can’t edit custom post type
- How can we take into account post types when constructing permalinks?
- 404 Issue w/ Custom Post Type – using Meta for Permalink rewrite
- Get Taxonomy Term Title by it’s URL
- Set URL link to featured image of custom post type
- Taxonomy custom post type URL
- How to change custom post type permalink structure
- Change CPT archive title
- AJAX load more for different custom post type loops
- PHP variable not regenerating when publishing multiple posts at the same time
- Front custom edit post page for each post
- Adding custom post category slug in permalink causes 404 error for pages and posts
- Categories of Custom Post throws gives 404
- On update or create post redirect to current post position in list
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- I need to add endpoint for wordpress categories
- How to build custom route by adding taxonomies to URL ? ex: www.demo.com/communities/palo-alto/
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- How to target a specific custom post type post and its all children and grandchildren?
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- Custom rewrite url category
- Featured image overlay when changing post status
- Rewrite Question Mark in Post Template to Make it Pretty URL
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- get_post_meta not working on publishing
- Index page with the same id as the slug
- Redirect 404 page with ID in slug to associated page with same ID in slug
- WordPress wrapped added a span tag to every single p tag
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- Display featured image from one CPT within another CPT query
- How can I make the slug of the taxonomy also the slug of the custom post
- Query taxonomy of taxonomy of custom post type
- Best way to style first post differently?
- WordPress custom post type permalink rewrite shows page not found
- Using taxonomy term in CPT permalink – Pages 404’s
- How to make custom posts types display when published for the future
- How to add rewrite rule to custom post type with parent in url with cpt ui?
- Custom post type as home page with custom url
- Customize Custom Post Type URL
- Custom post URL 404 error
- Programmatically rewriting slug through functions.php but returns 404
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- URL rewrite add author as base
- create a new page from a custom post type similar to an authors page
- CPT archive admin menu label
- Anon function and add_meta_box
- Custom Permalink to remove category word , keeping posts permalink with date?
- Set a CPT slug as a base name for all the taxonomies
- Custom taxonomy rewrite with query var returns %2F in URL
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- Remove slug in URL custom post type
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Rewrite custom post type url – Multiple post types
- Why isn’t my custom post type archive URL translating?
- Custom Post Type and Category Base Rewrite Issue
- Versioned Custom Post Type (Not the same as revisions)
- Rewrites/query for multiple hierarchical custom post types
- WordPress custom post type split into pages
- cpt and page sharing same base permalink
- WordPress uses url different from defined in rewrite arg of custom post type
- Rewrite URL of Custom Post Type for Jobs
- Hide a widget inside a div on specific type of post
- Custom post Type, child of a Page?
- Hide or disallow default custom post type url?
- Shortcode not working with post counter
- URL rewriting for CTP assigned entity
- Changing default ‘posts’ parameters with register_post_type_args
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom taxonomy returns 404
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Cannot save CPT meta box
- Including taxonomy term before post type breaks top level pages
- Correct procedure for advanced permalinks
- Custom Post Types hierarchy and rewrite
- Allow users to create posts without logging in?
- CPT’s with landing page instead of archive – Url Rewrite?
- How to change permalink to include custom post type
- How to get list of taxonomy slugs ordered parents>childs?
- Rewrite rule for Custom Post Type Page as a parent
- Added Custom Post Type and the View Option Doesn’t Work
- Rewrite Endpoints and CPTs – How to use in a plugin
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Add term to custom post type on draft
- add_rewrite_rule and passing variables for custom post types
- Pretty URLs and custom post types