Issue with get_fields_html

Forums Forums Search & Filter Pro Issue with get_fields_html

Viewing 7 posts – 1 through 7 (of 7 total)
  • Anonymous
    #169120

    Hi,

    Have an issue trying to extract post types via $postTypes1 = $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”));
    echo $postTypes1;

    only returns
    Access Levels: All Access Levels (ie: _sft_access_level)
    Topics: All Topics (ie: _sft_topic)

    but no post types aka Data Type.

    You can see the page results here:

    The debug structure of the query which clearly shows them here:
    Please see image link
    or
    Issue with get_fields_html

    Is this a bug with get_fields_html?

    If the Data Types are checked as filters it’s possible to retrieve them but that is different from retrieving the associated post types via get fields.

    	<?php  	
    		$postTypes1 = $sf_current_query->get_fields_html(array("_sf_s", "_sft_access_level", "post_type","_sft_topic"));
    		echo $postTypes1; 
    		//echo $sf_current_query->is_filtered();
    		$postTypesAll = $sf_current_query->get_array();
    		//var_dump($postTypesAll);
    		//print_r(array_values($postTypesAll));
    		$postTypes = array_column($postTypesAll, 'active_terms');
    		//var_dump($postTypes);
    		//print_r(array_values($postTypes));
    		$newArray = array();
    		foreach ($postTypes as $entry) {
    			$names = array_column($entry, 'name');
    		}
    		//var_dump($names);
    		//print_r(array_values($names));
    		$dataTypes = "<br>Data Types: ";
    		$breakChars = ", ";
    		//echo $dataTypes;
    		for ($i = 0; $i < count($names); $i++) {
    			$nameCompare = strcmp($names[$i], "Posts");
    			if ($nameCompare == 0) {
    				$names[$i] = 'Articles';
    			}
    			//echo $names[$i];
    			if ($i < count($names) - 1) {
    				echo $breakChars;
    			}
    		}
    		//var_dump($names);
    		//print_r(array_values($names));
    	?>
    Trevor
    #169154

    Are you trying to get terms from the results array? This search shows other user posts that fetch data from the array:

    https://support.searchandfilter.com/forums/search/sf_current_query+active_terms/

    Anonymous
    #169216

    No, I’m trying to get the post_type from $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”));

    You can see it in the image under form_fields/post_type/post_types

    Why are they not formatted in $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”)); as in the other array entries?

    Trevor
    #169218

    I do not think that method will work. I dump the array using print_r, as you seem to have done, then access the specific array term. Which is what those other users do.

    Anonymous
    #169225

    I’ve done that already, if you look at the bottom code in the original post.

    So what you’re saying is that you can’t access it via $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”)); despite “post_type” being in there?

    There’s not a lot of documentation on it so it’s difficult to know exactly what is to be expected here.
    The https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/ page just has examples but doesn’t explain much.

    Trevor
    #169245

    But I don’t access it using get_fields_html. I do it like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(934)->current_query()->get_array();
    $my_post_type = $sf_current_query[post_type][active_terms][0][value];
    Anonymous
    #169289

    Ok, so I was right to use get_array() in the first place (excuse the long winded method, it was for debugging purposes).

    The documentation is lacking a little in this regard, so I suggest you clarify the use and differences between get_array() and get_fields_html. The expectation is that if it’s in form_fields you should be able to extract it via get_fields_html into an output string, whereas in you actually need to use get_array() and format the output yourself. In this case we also need to replace a name as well.

    ty.

Viewing 7 posts – 1 through 7 (of 7 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.