You can avoid infinite loop by removing the action before calling update post function.
function maybe_disable_comment($post_id) {
// do you check if the post has specific custom tax term.
if ( ! has_term( 'bar', 'YOUR_CUSTOM_TAX', $post_id ) ) {
return false;
}
// remove the filter that will create infinite loop.
remove_action( 'wp_insert_post', 'maybe_disable_comment' );
// disable comment.
wp_update_post( array(
'ID' => $post_id,
'comment_status' => "closed"
) );
// add the action again. (so that next post update hook is handled properly)
add_action( 'wp_insert_post', 'maybe_disable_comment' );
}
add_action('wp_insert_post', 'maybe_disable_comment');
Related Posts:
- Hierarchical taxonomy UI
- ‘wp’ action hook not firing in admin and login?
- Unexpected results from get_taxonomies() and {$taxonomy}_edit_form and related hook
- put custom taxonomy slug in front of their respective term slugs
- Is it safe to register a taxonomy without using any hooks?
- What is the action hook that deletes a taxonomy term from the backend? And how to retireve the term id before deleting it?
- How to Modify Default Text in a Custom Taxonomy Admin Panel?
- Reverse order of posts in a certain taxonomy archive?
- Display taxonomy with a maximum number of letters
- Is there a way to change select-list for new custom taxonomy?
- use apply_filters return taxonomies custom post type
- deleted_$taxonomy not getting fired
- Custom button on custom taxonomy listing page
- How can I get the term_id from the action hook ‘set_object_terms’?
- Hook to filter based on form value and insert term
- WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?
- Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’
- Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)
- Get value in custom field with taxonomy [closed]
- Get second level terms of custom taxonomy
- Modify Term Update Redirection
- How to get first post in a category of a custom taxonomy
- How to get the singular name of a custom taxonomy?
- Archive template for taxonomy terms
- pre_get_posts OR relation between taxonomy and author
- Custom Fields and performance
- Non-hierarchical custom taxonomy using checkboxes on edit-screen -> saving issue
- Dynamic page slug for Custom Taxonomies?
- show term description instead of list terms of custom taxonomy
- get_the_term_list without specific category
- Add Category Name to REST API
- Display the Terms from a Custom Taxonomy Assigned to a Post(inside the loop) in Hierarchial Order
- Edit post meta with checkboxes on front end
- drop-down list taxonomy problem
- Redirect to Post List by Taxonomy on User Selection of Taxonomy Dropdown?
- How do I get WordPress URL rewrites into Sitemap?
- How to display custom taxonomy in multiple columns?
- Custom taxonomy sort by term meta in admin columns
- Programatically added attribute, set to ‘show on product page’ automatically. Woocommerce [closed]
- WordPress Custom Taxonomy – Volume / Issue – Unique Slug Issue
- How to show the entries in a custom taxonomy by author?
- Get Current Custom Taxonomy ID by Post ID
- Custom fields to taxonomy
- Correct way to insert taxonomies on page insert
- Styling Taxonomy Terms Individually
- Get terms cross-taxonomy query
- Custom Taxonomy Template Error: Catchable fatal error: Object of class WP_Error could not be converted to string
- Custom Taxonomy in default RSS feed
- How to make custom post taxonomy looks like regular categories?
- Create Geographical regions -> countries structure and relationship with taxonomies
- Custom Taxonomy Term Archive Page Template that Filters 2 or more Taxonomies
- Custom taxonomy link opens under Posts
- Changing URLs for taxonomies and CPT
- Front-End Custom Taxonomy Tag Select
- Set tax_query conditionally with new WP_Query
- how to store values in database at hierarchical view
- Strip tags from a the terms() function
- Why can’t I use an array of term slugs in WP_Query?
- Using wp_dropdown_categories in widget options
- Custom taxonomy archive page requires ?post_type= in url
- Custom taxonomy terms not showing as list Gutenberg Editor WordPress
- Twin value tags as an esoteric taxonomy
- Adding a custom taxonomy to “nav_menu_item”
- Clean Custom URL for Serach + Custom Taxonomy
- Advanced search redirecting to another page then filter further
- pagination not working on custom-taxonomy template
- Limit Display Number Of Taxonomy Term
- Custom arguments in WP_Query
- Sort and paginate custom post taxonomies alphabetically
- Current taxonomy name (not term!) given a post ID
- Search box with field hidden till drop down selection is made
- 404 Error on Custom Post Type / Custom Taxonomy
- Unsetting post_tag taxonomy breaks term description for other taxonomies
- Taxonomies on Pages with Custom Formatting
- Prioritise Pages over Taxonomy Term Root Archive, but not Taxonomy Term Child Archives
- Showing custom taxonomy in woocommerce signle product page
- Custom taxonomy not showing in grid view for ‘attachment’ post type
- How To Create Dynamic Permalink To Custom Taxonomy List of Current Posts?
- How to create archive pages for metadata query generated posts (so without taxonomy)?
- How to get list of custom taxonomies based on custom post type
- how to filter the data’s comparison operators (>= &
- Rewrite rule pagination on different url levels
- Sort Taxonomy List by Custom Values
- How to filter a taxonomy meta field to the ‘single_term_title’ filter hook
- Custom taxonomy rewrite in permalinks for posts gives 404 on pages
- Query pages by child term
- Custom taxonomy applied to links [duplicate]
- Custom Taxonomy registered with multiple custom posts
- Insert term description programmatically into hierarchical custom taxonomy
- Custom Taxonomy + JQuery Tabs
- Get all taxonomy posts by id
- Custom Taxonomy Template Variables Available?
- i need to show featured post on custom taxonomy page
- Taxonomy to display form after creation
- How home my code doesn’t display any feature image? Looping through post from a taxonomy and not getting feature images back
- Add taxonomy fields of posts into RSS feed
- Add text in custom taxonomy
- How do I check if a post has a term with a particular ancestor/parent?
- Best approach of implementing multi-select/checkboxes for taxonomies?
- Show taxonomy term meta field on single template