Forums Forums Search & Filter Pro How to get Post Meta values?

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #72711

    Hello, is there any particular way to “get” the post meta values, similar to the way we can grab other search data?

    For example:

    <?php
    	global $searchandfilter;
    	
    	$sf_current_query = $searchandfilter->get(1526)->current_query();
    	
    	$sf_current_query->get_search_term();
    ?>

    This lets us grab the current query’s search term. And custom taxonomy info can be grabbed through something like:

    <?php
    $sf_current_query->get_taxonomy_terms_string('_sft_types');
    ?>

    However what would be the proper syntax to use to get various post meta data? (And more specifically when we have a numeric range set, those min and max values)

    Thanks

    Trevor
    #72776

    What do you need to use this for? Is it for output on a results page?

    Anonymous
    #72832

    Yes, need it to interact with another plugin we’re using.

    Trevor
    #72844

    Are you looking for the search terms as shown in the URL when the form submits? I am not certain I know what it is you want.

    Anonymous
    #72850

    Right, when someone runs a search they get to a page with a URL like:
    http://example.com/results/?_sft_types=homes&_sfm_square-feet=3000+7500

    How can we grab the post meta value from that search, both the “3000” and the “7500” in that instance?

    Trevor
    #72856

    Ah, OK. I understand. The data is there in an array, so the actual terms need will vary according to your form and the fields you have used. This thread may give you some ideas:

    https://support.searchandfilter.com/forums/topic/how-to-style-the-search-data/

    Anonymous
    #72865

    If we can grab the meta data as an array, that might work fine. (The other plugin we’re using runs on WP_Query, so I think it should be able to take an array)

    I’ll check out that thread in the meantime though.

    Anonymous
    #73321

    Hi, we were able to get the meta values we needed with get_array();

    And for those curious the code we used was (square-feet is our custom field):

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(315)->current_query();
    
    $array_data = $sf_current_query->get_array();
    $squarefeet_min = $array_data["_sfm_square-feet"]["active_terms"][0]["value"];
    $squarefeet_max = $array_data["_sfm_square-feet"]["active_terms"][1]["value"];
    ?>

    Thanks again for the help.

    Trevor
    #73340

    Great and thanks for sharing 🙂

    I will close this thread as resolved then.

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