sf_edit_query_args with meta data

Forums › Forums › Search & Filter Pro › sf_edit_query_args with meta data

Viewing 4 posts – 1 through 4 (of 4 total)
  • Anonymous
    #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
    #126678

    If 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/

    Anonymous
    #126712

    thanks! I’ll give this a shot and let you know how it works out

    Anonymous
    #126734

    that worked, thank you!

Viewing 4 posts – 1 through 4 (of 4 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.