ACF / Post Meta Fields in current_query() Result

Forums › Forums › Search & Filter Pro › ACF / Post Meta Fields in current_query() Result

Tagged: ,

Viewing 4 posts – 1 through 4 (of 4 total)
  • Anonymous
    #249698

    My S&F is entirely filtering on ACF fields as post meta results.

    I’d like to display the selected search terms, however there seems to be a difference in how to get these vs more standard fields like category.

    For example:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    echo $sf_current_query->get_field_string("_sft_category");

    gives the expected result, but changing the argument in the third line to be a custom field using the name that appears in the url bar(?_sfm_work_type=26-%2C-27&_sfm_industries=14-%2C-15) doesn’t give any results, even though the filter works fine.

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    echo $sf_current_query->get_field_string("_sfm_industries");

    Is there a change in method to get those fields?

    Trevor
    #249704

    You first need to find out where the data is, and to do so you need to examine the filter array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    This will print that array to the screen. From that you would need to use code LIKE this:

    echo $sf_current_query['_sft_category']['active_terms'][0]['name']

    This would echo out the first Category term. You will need to write a similar line, for example:

    echo $sf_current_query['_sfm_industries']['active_terms'][0]['name']

    Anonymous
    #263899

    gotcha, thanks.

    Trevor
    #263904

    If that works for you, is OK to close this thread?

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.