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_multiple_check_filter_relation

This hook can be used to change the relation to filter the posts in Multiple checkbox filter.

add_filter('tc_caf_multiple_check_filter_relation', 'tc_caf_multiple_check_filter_relation', 10);
function tc_caf_multiple_check_filter_relation() {
return 'AND';
}

3) 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) {
//var_dump($tax_query);
//var_dump($filter_id);
//var_dump($terms);
return $tax_query;
}

4) 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. Hope 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;
}

5) 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;
}
}

Was this article helpful to you? Yes 2 No 1

How can we help?