Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

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

Tagged: ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Marc Schroeder
    #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 Moderator
    #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']

    Brian Sirkia
    #263899

    gotcha, thanks.

    Trevor Moderator
    #263904

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

Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.