Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danielpowney/66f83153149542ea5588 to your computer and use it in GitHub Desktop.
Save danielpowney/66f83153149542ea5588 to your computer and use it in GitHub Desktop.
<?php
/**
* Sets default rating form for a post based on category
*
* @param int $rating_form_id
* @param int $post_id
* @param array $params
* @return $rating_form_id
*/
function mrp_default_rating_form_by_category( $rating_form_id, $post_id, $params ) {
if ( $post_id ) {
$terms = get_the_terms( $post_id, 'category');
if ( $terms && is_array( $terms ) ) {
if ( in_array( 'category1', $terms ) ) {
$rating_form_id = 1;
} else if ( in_array( 'category2', $terms ) ) {
$rating_form_id = 2;
}
}
}
return $rating_form_id;
}
add_filter( 'mrp_default_rating_form', 'mrp_default_rating_form_by_category', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment