/**When working with GD Dynamic Content and GD Post Badge widgets, you can use the following code snippet to add custom conditions such as is_contains_any and is_not_contains_any to your shortcodes.
Here is an example of such usage:*/
[gd_dynamic_content key="package_id" condition="is_contains_any" search="3,11,15"]DO SOMETHING[/gd_dynamic_content]
/ ** Adding Custom Conditions */
function wpsc_gd_snippet_badge_conditions( $conditions ) {
$conditions['is_contains_any'] = __( 'is contains any of', 'geodirectory' );
$conditions['is_not_contains_any'] = __( 'is not contains any of', 'geodirectory' );
return $conditions;
}
add_filter( 'geodir_badge_conditions', 'wpsc_gd_snippet_badge_conditions', 10, 1 );
function wpsc_gd_snippet_dynamic_content_check_match_found( $match_found, $args, $find_post ) {
if ( ! empty( $args['condition'] ) && in_array( $args['condition'], array( 'is_contains_any', 'is_not_contains_any' ) ) ) {
$match_found = false;
$match_field = $args['key'];
if ( isset( $find_post->{$match_field} ) && trim( $find_post->{$match_field} ) !== '' ) {
$match_value = geodir_strtolower( stripslashes( $find_post->{$match_field} ) );
$search_value = geodir_strtolower( stripslashes( $args['search'] ) );
$match_value = explode( ",", $match_value );
$search_value = explode( ",", $search_value );
foreach ( $search_value as $value ) {
$value = trim( $value );
if ( $value !== '' && in_array( $value, $match_value ) ) {
$match_found = true;
break;
}
}
if ( $args['condition'] == 'is_not_contains_any' ) {
$match_found = $match_found ? false : true;
}
}
}
return $match_found;
}
add_filter( 'geodir_dynamic_content_check_match_found', 'wpsc_gd_snippet_dynamic_content_check_match_found', 10, 3 );