Forums › Forums › Search & Filter Pro › sf_edit_query_args with meta data
- This topic has 3 replies, 2 voices, and was last updated 7 years, 9 months ago by
Anonymous.
-
Anonymous(Private) August 18, 2017 at 4:30 pm #126664
Hello,
I am trying to add a custom filter to search a meta field, based on an input field that the user types in.
function filter_function_name( $query_args, $sfid ) { //if search form ID = 1880, then do something with this query if($sfid==1880) { //modify $query_args here before returning it $meta_query = array( 'key' => 'NAM-Authors', 'value' => $query_args['s'], 'compare' => 'LIKE' ); $query_args['meta_query'] = array($meta_query); } return $query_args; } add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
This is not returning the results I am looking for. Any idea what I am doing wrong? Thank you for your time.
Trevor(Private) August 18, 2017 at 7:29 pm #126678If I understand you correctly, you are trying to search a meta key using the text search field? If so, you need to do this differently (not with that filter).
You can use Relevanssi to do this (the free version). You would need to enable the Relevanssi option in the advanced settings in our plugin, and setup the free Relevanssi plugin to include indexing that custom field. There is a settings field for custom fields in the Relevanssi plugin. See here:
https://www.designsandcode.com/documentation/search-filter-pro/3rd-party/relevanssi/
-
AuthorPosts