Skip to content

Instantly share code, notes, and snippets.

@pixelbart
Created March 22, 2021 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelbart/f24440e8ef53c288ac9670d6a1e2d133 to your computer and use it in GitHub Desktop.
Save pixelbart/f24440e8ef53c288ac9670d6a1e2d133 to your computer and use it in GitHub Desktop.
Disable Helpful in a specific term of a taxonomy
<?php
/**
* Disable helpful on new posts with specific term of taxonomy.
*
* @param int $post_id
* @param WP_Post $post
* @param bool $update
*
* @return void
*/
function hide_helpful_on_new_posts( $post_id, $post, $update ) {
if ( $update || wp_is_post_revision( $post_id ) ) {
return;
}
/* to change: term from taxonomy */
if ( ! has_term( 'term', 'taxonomy', $post_id ) ) {
return;
}
update_post_meta( $post_id, 'helpful_hide_on_post', 'on' );
}
/* init hide_helpful_on_new_posts on post save */
add_action( 'save_post', 'hide_helpful_on_new_posts', 10, 3 );