Forums › Forums › Search & Filter Pro › Filter by meta_query custom field
Tagged: filter, meta_query
- This topic has 10 replies, 2 voices, and was last updated 6 years, 3 months ago by
Anonymous.
-
Trevor(Private) July 31, 2019 at 4:32 pm #217704
You do not appear to be setting that up as a function, per this documentation:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
And are you then placing it in the child theme function.php file?
Anonymous(Private) July 31, 2019 at 4:36 pm #217706Yes it is a function, I was just showing you only the parts which you needed to see, here is it all:
/** * USER PROFILE - Modify search form args */ function user_liked_products_search_filter( $query_args, $sfid ) { if ( $sfid == 26 ) { $query_args = array ( 'meta_query' => array( array( 'key' => '_likes', 'value' => 1, ), ), ); } return $query_args; } add_filter( 'sf_edit_query_args', __NAMESPACE__.'\\user_liked_products_search_filter', 100, 2 );Anonymous(Private) August 1, 2019 at 4:08 pm #217817Because I am in a
namespacedfile.Why PHP Namespaces
In short, PHP namespaces address the problem of isolation. Before they were introduced to PHP, if you had a function, class, or constant called, say, Validation_Error in one part of your code, you simply couldn’t have another one like that anywhere else.
Anonymous(Private) August 1, 2019 at 4:19 pm #217825I am using the same filter to modify the main shop search too. This one works fine:
function update_search_category( $query_args, $sfid ) { $query_args['tax_query'] = array( array( 'taxonomy' => 'product_cat', 'terms' => '20', 'operator' => 'IN', ), ); return $query_args; } add_filter( 'sf_edit_query_args', __NAMESPACE__.'\\update_search_category', 20, 2 );Anonymous(Private) August 1, 2019 at 4:32 pm #217831Currently I am not simply for dev purposes. However I just fixed the issue moments ago! That’s 2 fixes today for me, I am on a roll haha.
Does not seem I was writing the meta_query correctly:
Before:
$meta_query = [ 'key' => '_liked', 'value' => '1', 'compare' => 'LIKE', ]; $query_args['meta_query'] = $meta_query;After
$query_args['meta_query'] = array( array( 'key' => '_liked', 'value' => '4', 'compare' => 'LIKE', ), );For now decided to not do the declare at the top and then pull in below. This works so I’ll run with it for now.
Thanks for the responses Trevor, always appreciated.
-
AuthorPosts