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
- How come Featured Image isn’t showing up in my Custom Post Type?
- Mixing custom post type and taxonomy rewrite structures?
- How to use a custom post type archive as front page?
- How to rewrite URI of custom post type?
- Set posts of a custom post type to be private by default?
- Custom post types – Use post_id in permalink structure
- Custom Post Type and Taxonomy URL rewrite
- Rewrite custom post type rss feed links
- clients list using wordpress
- Archive page with multiple taxonomies rewrite
- rewrite get parameter with custom post type
- Date archives for custom post type
- How can I add dropdown widget/box to admin post page?
- Taxonomy page returns 404 page not found
- Remove unwanted part of permalink custom structure from CPT url?
- How to have a custom URL structure for a custom post type?
- Changing a custom post type “has_archive” after registered
- Custom Post Type rewrite redirects to homepage
- Custom Post Type slug same as page name causing a conflict
- Append taxonomy terms as class names in markup?
- Display only custom post type count for current author on the “At a Glance” dashboard widget
- Adding paged query to custom URL rewrite
- Customising rewrite rules for CPT single post URL to work as paged URL
- Remove custom post type slug not working for child pages
- Rewrite rules for custom post type slug
- GravityForm: Populate Dropdown with custom post type [closed]
- How to retrieve category NAME instead of ID in a function with a taxonomy custom field?
- Change URL of posts and also Custom Post Type
- Custom Post Type rewrite
- WooCommerce product search titles only
- Custom Taxonomy Permalinks Redirection
- Add custom column in custom post type edit page
- Remove url rewrites for registered taxonomies
- Get Taxonomy Term Title by it’s URL
- Change CPT archive title
- I need to add endpoint for wordpress categories
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- Featured image overlay when changing post status
- Using taxonomy term in CPT permalink – Pages 404’s
- Programmatically rewriting slug through functions.php but returns 404
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Why isn’t my custom post type archive URL translating?
- Hide a widget inside a div on specific type of post
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- Taxonomy in URL
- Warning: Invalid argument supplied for foreach() [closed]
- Custom post type isn’t working
- custom post for slider
- Navigate posts with different post type that are in the same categories
- Show Custom Message in WordPress Admin
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- How exclude or skip post type with get_next_post_link
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- Create short URL with auto 301 redirect
- Is it possible to use array_walk() to append terms to an array of posts?
- WordPress notification if new post published
- How do I know if a rewritten rule was applied?
- How Can I Remove Custom Post Type Slug From URL
- WordPress custom permalink and archive link for custom post type
- Custom Post Types and Removing Slugs – should we do it?
- Twitter Product Cards
- Taxonomy rewrite pagination 404
- Excerpt length: get first paragraph
- new post-type how do i retain the plugins on my sidebar?
- Remove cpt slug from url and use custom taxonomy instead breaks all other cpt
- Custom Post Type Dashboard Tab not displaying any posts
- Title and URL Error in Breadcrumb Navigation for Custom Post Types
- How to properly set the rewrite rules for this case?
- Assigning categories to custom post types via a front-end form; only works for native post type
- Default excerpt for parent of a custom post type
- Move to trash custom post type post after ACF Date Picker date is older than today
- How to fix 404 on post after prepending Custom Post Type url with Custom Taxonomy Term slug
- Load custom post type with ID in a shortcode
- Custom post type structure + permalink structure
- Rewrite URL of Specific Post of Custom Type
- Custom permalink rewrite rules – how do I fix this?
- Populate custom post type/custom fields from an external database
- Work and Display a Custom Post Type as a normal Post
- Custom Field to post_title
- Post Custom & Taxonomy 404 error
- How To Display Category list from Portfolio post type plugin?
- Remove custom post type slug but keep related category taxonomy permalink
- page not found for example.com/custom-post-name
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- Force WordPress to only match URL in category
- Cannot modify a registered custom post type rewrite slug
- Generating custom URL before post is published
- Allow authors to create article image
- Custom post type permalink structure
- Comments are not working on Custom Post Type
- Rewrite Rule for custom post type link with or without taxonomy terms
- Rewrite nested urls for custom post type
- Custom post type Premalinks main page and details page
- Rewrite rule taxonomy url with different values in one function