Forums Forums Search Search Results for 'sf_current_query'

Viewing 10 results - 61 through 70 (of 318 total)
  • Author
    Search Results

  • Trevor
    Participant

    You seem to have customised the results.php file, but it must have errors as it also shows ‘no results found’?

    This post might help you with code for what you want:

    https://support.searchandfilter.com/forums/topic/category-description-in-search-results/page/2/#post-236248

    That code is for _sft_category and the id number is wrong, so maybe this?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(3637)->current_query();
    $sf_current_query_array = $searchandfilter->get(3637)->current_query()->get_array();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>No category selected.</div>'; 
    } else {
      echo '<div>' . $sf_current_query_array["_sft_menucats"]["active_terms"][0]["value"] . '</div>';
      echo '<div>' . $sf_current_query_array["_sft_menucats"]["active_terms"][0]["id"]. '</div>';
      echo '<div>' . category_description($sf_current_query_array["_sft_menucats"]["active_terms"][0]["id"]). '</div>';
    }

    Otherwise, are you able to send me temporary WordPress admin logins (ones you should later delete or disable) for the site so that I can look at the setup? Please use a Private Reply.

    #236248

    Trevor
    Participant

    I added this code:

    https://www.screencast.com/t/WYIjHhwBYb

    This:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(332)->current_query();
    $sf_current_query_array = $searchandfilter->get(332)->current_query()->get_array();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>No category selected.</div>'; 
    } else {
      echo '<div>' . $sf_current_query_array["_sft_category"]["active_terms"][0]["value"] . '</div>';
      echo '<div>' . $sf_current_query_array["_sft_category"]["active_terms"][0]["id"]. '</div>';
      echo '<div>' . category_description($sf_current_query_array["_sft_category"]["active_terms"][0]["id"]). '</div>';
    }

    Anonymous
    Inactive

    Like this?

        <?php
        //grab the active query from our search form
    	//replace <code>1526</code> with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(3969)->current_query();
    	?>  

    Trevor
    Participant

    I assume the $sf_current_query is defined before that line?


    Trevor
    Participant

    Do you prefer the page to be empty, or maybe a message?

    It looks like you are using the Shortcode display results method, in which case you should follow the ‘guide to customising’:

    https://support.searchandfilter.com/documentation/search-filter-pro/search-results/using-a-shortcode/

    Once you have a copy of the results.php file in a search-filter sub-folder of your theme, you can edit that file, like this (leave the PHP comments at the top outside and before this code):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(3204)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // the current resuts.php code here
    }
    #234134

    Trevor
    Participant

    So, that would be:

    echo $sf_current_query["_sfm_city"]["active_terms"][0]["value"];

    I think.

    #234128

    Anonymous
    Inactive

    It really doesn’t give me anything different then what i see above.

    It shows what I queried but I simply need to display the Name of the City…when i attempt to use the first query i showed above to show _sfm_city it doesn’t display anything. How do i get the name of the city to display:

     [_sfm_city] => Array
            (
                [name] => 
                [singular_name] => 
                [all_items_label] => 
                [type] => post_meta
                [active_terms] => Array
                    (
                        [0] => Array
                            (
                                [name] => Caracas
                                [value] => Caracas
                            )
    
                    )
    
            )
    
    )
    <?php
    	//Get a single fields values using labels
    	//replace <code>1526</code> with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(1902)->current_query();
    	echo $sf_current_query->get_field_string("_sft_city");
    	
    ?>
    #234116

    Trevor
    Participant

    If you use this code you would get the whole array:

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

    Then you can see what each is called and contains.

    #234105

    Anonymous
    Inactive

    So i was able to use your documentation to grab the following query output: However, when i attempt to call the field _sfm_city it does not display anything. This is a Meta Key, does that matter? My attempt to display it is listed below

    
    Array
    (
        [_sft_specialties] => Array
            (
                [name] => specialties
                [singular_name] => Specialty
                [all_items_label] => All Items
                [type] => taxonomy
                [active_terms] => Array
                    (
                        [0] => Array
                            (
                                [id] => 355
                                [name] => Test Matter Type
                                [value] => test-matter-type
                                [count] => 1
                            )
    
                    )
    
            )
    
        [_sft_providers-category] => Array
            (
                [name] => Categories
                [singular_name] => Categories
                [all_items_label] => Categories
                [type] => taxonomy
                [active_terms] => Array
                    (
                        [0] => Array
                            (
                                [id] => 68
                                [name] => Patent Search
                                [value] => patent-search
                                [count] => 1
                            )
    
                    )
    
            )
    
        [_sft_operatingcountries] => Array
            (
                [name] => Operation Countries
                [singular_name] => Operating Countries
                [all_items_label] => All Operating Countries
                [type] => taxonomy
                [active_terms] => Array
                    (
                        [0] => Array
                            (
                                [id] => 145
                                [name] => Denmark
                                [value] => denmark
                                [count] => 1
                            )
    
                    )
    
            )
    
        [_sfm_city] => Array
            (
                [name] => 
                [singular_name] => 
                [all_items_label] => 
                [type] => post_meta
                [active_terms] => Array
                    (
                        [0] => Array
                            (
                                [name] => HARARE
                                [value] => HARARE
                            )
    
                    )
    
            )
    
    )

    `<?php
    //Get a single fields values using labels
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1902)->current_query();
    echo $sf_current_query->get_field_string(“_sft_city”);

    ?>

    #234049

    Trevor
    Participant

    The page title and that searched for part are both from the theme template, and not from our plugin. The template looks like it is a modified search.php or archive.php template that are only ever designed to display the search string, whereas you filter is far more complex.

    You may need to refer to the theme authors as to how to alter/set the page title. WordPress does have some functions also to do this, but whether they would work would depend on the theme in use.

    To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

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

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    You also look like you need some custom CSS:

    .searchandfilter > ul {
      margin-left: 0;
    }
Viewing 10 results - 61 through 70 (of 318 total)