Forums › Forums › Search & Filter Pro › Amending WP_Query for a form with a dynamic variable
- This topic has 8 replies, 4 voices, and was last updated 6 years, 1 month ago by
Anonymous.
-
Anonymous(Private) June 9, 2019 at 9:44 pm #213626
Hi TJ,
On your second example, did you try adding:
global $arr_product_ids
within the function too? Your trying to use $arr_product_ids variable.function filter_function_name( $query_args, $sfid ) { if($sfid==2978) { global $arr_product_ids; $query_args['post_product'] = $arr_product_ids; } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
Anonymous(Private) June 9, 2019 at 9:47 pm #213628TJ, another quick example maybe to help:
function filter_function_name( $query_args, $sfid ) { if($sfid==2978) { global $arr_product_ids; $query_args['tax_query'] = array( array( 'key' => 'post_product', 'value' => $arr_product_ids, 'compare' => 'IN', ), ); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
Ross Moderator(Private) June 11, 2019 at 6:51 pm #213829Hi Holly
I tried your code and it didn’t affect my setup at all (it should show no results, as that taxonomy doesn’t exist in my setup…)
So… I had to double check the WP docs as it seemed like your tax query was ok on first glance but its not.
I tried your code swapping out taxonomies for something I had in a testing environment and it didn’t work either (its much the same as yours):
$query_args['tax_query'] = array( array( 'key' => 'cptuicat', 'value' => array(9), 'compare' => 'IN', ) );
I checked the docs and actually it should look like I think:
$query_args['tax_query'] = array( 'relation' => 'AND', array( 'taxonomy' => 'cptuicat', 'field' => 'id', 'terms' => array( 9 ), ), );
This worked for me, the ID of
9
being a taxonomy term I have…If you copy and paste that, and swap out what you need then I think it should work.
Let me know how you get on.
Thanks
Ross Moderator(Private) June 11, 2019 at 6:53 pm #213831Actually looking at your code, it looks like your structure is for a
meta_query
not atax_query
🙂 -
AuthorPosts