1. Home
  2. Docs
  3. Documentation
  4. Developers
  5. Hooks To Use

Hooks To Use

1) tc_caf_filter_order_by

You can sort the filter categories by the use of this hook.

add_filter('tc_caf_filter_order_by', 'tc_caf_function_filter_order_by', 10);

function tc_caf_function_filter_order_by($terms) {
sort($terms);
return $terms;
}

 

2) tc_caf_filter_posts_tax_query

This hook can be used to change the tax_query parameters of WP_QUERY.

add_filter('tc_caf_filter_posts_tax_query','tc_caf_filter_posts_tax_query_fun',10,3);

function tc_caf_filter_posts_tax_query_fun($tax_query,$filter_id,$terms) {
return $tax_query;
}

 

3) tc_caf_filter_posts_query

This hook can be used to change the WP QUERY Arguments. You can use this to add meta_query arguments to filter with Custom Fields.

Note:- We are using this filter hook function to filter posts that has special custom field of ‘eventdate’. So now query filter upcoming events. We are comparing eventdate with Today Date. It helps to create query with custom field.
add_filter('tc_caf_filter_posts_query','tc_caf_filter_posts_query_fun',10,2);

function tc_caf_filter_posts_query_fun($args,$filter_id) {
$args['meta_query'] = array(
array(
'key' => 'eventdate',
'value' => date('Y-m-d'),
'compare' => '>=',
'type' => 'date'
)
);
$args_new = array('orderby' =>'meta_value','suppress_filters' => false);
$args_updated=array_merge($args,$args_new);
return $args_updated;
}

 

4) tc_caf_filter_posts_query

This hook is used for to change the order by any custom field key. In this example , we are ordering posts by event_date that is a meta field created by advanced custom field plugin.

add_filter('tc_caf_filter_posts_query','tc_caf_filter_posts_query_fun',10,2);

function tc_caf_filter_posts_query_fun($args,$filter_id) {
if($filter_id=='13495') {
$args_new = array('orderby' =>'meta_value_num','meta_key'=>'event_date','suppress_filters' => false);
$args_updated=array_merge($args,$args_new);
return $args_updated;
}
else {
return $args;
}
}

 

5) tc_caf_multiple_tax_label_filter

This hook is used to change the labels of Multiple Taxonomy Filter.

add_filter('tc_caf_multiple_tax_label_filter','tc_caf_multiple_tax_label_filter_fun',10,2);

function tc_caf_multiple_tax_label_filter_fun($tax,$id) {
if($tax=='topic') {
return 'topic';
}
else if($tax=='level') {
return 'Levels';
}
else {
return $tax;
}
}

 

How can we help?