Created
July 25, 2015 10:23
-
-
Save danielpowney/66f83153149542ea5588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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