Filter with a custom attribute
-
Hi,
I have a custom attribute “instructor” I wish to create a filter to use this attribute.
I have added the below code to my functions.php but it doesnt appear to be working, could you please shed some light?
<?php
add_filter(’em_events_get_default_search’,’my_em_styles_get_default_search’,1,2);
function my_em_styles_get_default_search($searches, $array){
if( !empty($array[‘Instructor’]) && is_numeric($array[‘instructor’]) ){
$searches[‘instructor’] = $array[‘instructor’];
}
return $searches;
}add_filter(’em_events_get’,’my_em_styles_events_get’,1,2);
function my_em_styles_events_get($events, $args){
if( !empty($args[‘instructor’]) && is_numeric($args[‘instructor’]) ){
foreach($events as $event_key => $EM_Event){
if( !in_array($args[‘instructor’],$EM_Event->styles) ){
unset($events[$event_key]);
}
}
}
return $events;
}add_action(’em_template_events_search_form_ddm’, ‘my_em_styles_search_form’);
function my_em_styles_search_form(){
$my_em_styles = (is_array(get_option(‘my_em_instructor’))) ? get_option(‘my_em_instructor’):array();
?>
<!– START Styles Search –>
<select name=”Instructor”>
<option value=”>Instructor</option>
<?php foreach($my_em_styles as $style_id=>$style_name): ?>
<option value=”<?php echo $style_id; ?>” <?php echo ($_POST[‘instructor’] == $style_id) ? ‘selected=”selected”‘:”; ?>><?php echo $style_name; ?></option>
<?php endforeach; ?>
</select>
<!– END Styles Search –>
<?php
}function my_em_styles_accepted_searches($searches){
$searches[] = ‘instructor’;
return $searches;
}
add_filter(’em_accepted_searches’,’my_em_styles_accepted_searches’,1,1);
?>
- The topic ‘Filter with a custom attribute’ is closed to new replies.