-
Search Results
-
Hi there,
I have search and filter form where I need to set a custom meta query based on the values held within a dynamic array variable based on the user who is logged in (which controls what they see).
So manually I tried the following:
Post Meta > post_product = 1134
Which is similar to what I want, and of course that works BUT I need the value of that query to be a dynamic array of product ID’s instead (held within $arr_product_ids in my example) depending on the user logged in, ie as follows:
'meta_query' => array( 'key' => 'post_product', 'value' => $arr_product_ids, 'compare' => 'IN', ),With that in mind, I have tried: https://searchandfilter.com/documentation/search-results/custom/ and added the following to my functions.php file but sadly this has not worked:
global $arr_product_ids; $args = array( 'post_type' => 'post', 'posts_per_page' => 12, 'category_name' => 'news', 'meta_query' => array( 'relation' => 'AND', 'post_product' => array( 'key' => 'post_product', 'value' => $arr_product_ids, 'compare' => 'IN', ), 'post_urgent' => array( 'key' => 'post_urgent', 'compare' => 'EXISTS', ), 'post_priority' => array( 'key' => 'post_priority', 'compare' => 'EXISTS', ), ), 'orderby' => array( 'post_priority' => 'DESC', 'post_urgent' => 'DESC', 'date' => 'DESC' ), ); $args['search_filter_id'] = 2978; $query = new WP_Query($args);I then looked at https://searchandfilter.com/documentation/action-filter-reference/ and tried adding the following to functions.php, but sadly again no luck:
function filter_function_name( $query_args, $sfid ) { if($sfid==2978) { $query_args['post_product'] = $arr_product_ids; } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );Please could you ket me know where I’m going wrong with this as I think I’m going around in circles sadly, whereas you will know the issue immediately I’m sure :).
Many thanks,
TJ