Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 331 through 340 (of 344 total)
  • Author
    Search Results
  • #33259

    Anonymous
    Inactive

    Hi Ross,

    I’m still having an issue with getting the (new) search term when someone starts a new search from the search results page filters. As part of the filter setup on the results page, there is a search box to ‘start a new search’ if the site visitor isn’t seeing the results they want.

    However, when they search on a new phrase, the new search term is reflected in the URL and the results, but not in the text at the top of the page that says “Search Results for [search term]”.

    I posted about this previously here:
    https://support.searchandfilter.com/forums/topic/search-variable-s-versus-_sf_s/

    And I did add the suggested code to my template (search-deals.php), which to the best of my recollection was working fine then, or if not I may not have tested adequately to notice.

    The odd thing is that if I refresh (reload) the page of search results, then it updates the verbiage and is correct, but if I just enter a new search term and hit enter, then the page isn’t actually being reloaded, so the verbiage doesn’t change.

    SO my sequence is this: On the home page I have a S&F Pro search box (no filters, just a search box) and it’s set to display results on search-deals.php. On that template is called the results page filter, which lets visitors filter their results and that filter includes a(nother) search box to start a new search if they want to. That Filter is also set to display results on search-deals.php.

    SO on search-deals.php I have the following code:

    <?php 
    	$search_term = "";
    	
    	//get global S&F object
    	global $searchandfilter;
    	$current_query = $searchandfilter->get(725)->current_query(); //(NOTE 725 is the ID of my search results page filter)
    	
    	//check to see if a term has been found under the regular WP variable
    	//if not, try the S&F object
    	
    	if(get_search_query()!="")
    	{
    		$search_term = get_search_query();
    	}
    	else if($current_query->get_search_term()!="")
    	{
    		$search_term = $current_query->get_search_term();
    	}
    	
    ?>
    
    <header class="entry-header">
    	<h2 class="entry-title"><?php printf( esc_html__( 'Search Results for: %s', 'quark' ), '<span>&ldquo;' . $search_term . '&rdquo;</span>' ); ?></h2>
    </header>

    The problem is with the last bit – the header that write to the page the “search results for: %s” – I’m not sure how to *replace* the original search term for the new one as ‘%s’ even though the page URL is updated fine and the results are updated and correct for the new search term.

    I hope this makes sense!

    As always thanks for your wonderful support! 🙂

    #31935

    Anonymous
    Inactive

    So I’ve been trying to pull the field name from the Active Query Object, but I’m not able to pull any of custom fields, just categories.

    I’m able to get _sft_credit_card_category, but not the post_meta fields of _sfm_issuer and _sfm_credit_quality.

    
    <?php
    //grab the active query from our search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(615)->current_query();
    var_dump($sf_current_query->get_array());
    
    echo $sf_current_query->get_field_string("_sft_credit_card_category");
    echo $sf_current_query->get_field_string("_sfm_issuer");
    echo $sf_current_query->get_field_string("_sfm_credit_quality");
    ?>
    
    #31706

    Ross
    Keymaster

    Hi Stephen

    The active query class is not currently too well documented (as its just been created its subject to change a little) but you can certainly change the output of this field.

    Please take a look at this example:

    $args = array(
    	"str" 				=> '<strong>%1$s</strong>: %2$s',
    	"field_delim" 			=> '<hr />'
    	
    );
    echo $sf_current_query->get_fields_html(array("_sft_category", "_sft_post_tag"), $args);

    You can see str variable is the format output of html for each field, in the example above I’ve added <strong> tags around the name

    The next is field_delim – this is what is used to join the strings for each field – default is <br /> but you can change this to anything.

    I think with these two arguments there should be no issues with formatting the way you want.

    Thanks

    #31297

    Anonymous
    Inactive

    I’m trying to output the filtered data using your instructions on the Accessing the Search Data page (http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/). However, the outputted field names and respective data are not wrapped in any sort of html tag.

    I would like the output to look something like this:

    <div class=”filterdata”>
    <div class=”fieldname”>Categories:</div>
    <div class=”fielddata”>Community<br/>Arts</div>
    </div>

    Is that possible by manipulating the sf_current_query?

    #30637

    Anonymous
    Inactive

    Just to be clear. The code below:

    <?php

    $sf_current_query = $searchandfilter->get(14458)->current_query();
    echo $sf_current_query->get_field_string(“_sft_category”);

    ?>

    Results: Categories: All Categories

    It doesn’t display the category that the post is assigned to when using the code:

    Categorized in: <?php the_category(); ?>

    #30635

    Anonymous
    Inactive

    Hey Ross,

    Did you try it on the results.php located in the avada theme folder /search-filter ?

    I tried this again with the following two codes;

    <?php
    //Get an array of objects containing data for the current search/filter
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(14458)->current_query();
    var_dump($sf_current_query->get_array());
    ?>

    and

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

    ?>

    Neither are able to pull the values I need.

    I’d like to turn the Categories In: line to not be bulleted and be on the same line. If I can pull the category then it would be fine.

    I tried the above codes at the top of the results.php and neither worked.

    Any idea why ?

    #30310

    Anonymous
    Inactive

    That doesn’t work. I used the following code:

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

    The output is:

    Categories: All Categories

    What I had before was better since it displayed the proper category.

    What I’m looking for is a way to display:

    Category: CategoryName

    And have the category linked to display the output as if selecting from the dropdown instead of a different layout.

    This is the current page below which is almost there.

    http://whazat.ca/resource-library/

    #29536

    Ross
    Keymaster

    Hey Trisha

    Something like this should work:

    <?php 
    	$search_term = "";
    	
    	//get global S&F object
    	global $searchandfilter;
    	$current_query = $searchandfilter->get(1526)->current_query();
    	
    	//check to see if a term has been found under the regular WP variable
    	//if not, try the S&F object
    	
    	if(get_search_query()!="")
    	{
    		$search_term = get_search_query();
    	}
    	else if($current_query->get_search_term()!="")
    	{
    		$search_term = $current_query->get_search_term();
    	}
    	
    	printf( esc_html__( 'Search Results for: %s', 'quark' ), '<span>"' . $search_term . '"</span>' ); 
    	
    ?>

    I didn’t test it yet but looks sound.

    Thanks

    #26959

    Anonymous
    Inactive

    Just an update.
    I tried to use following code but it seems that a function does not exists:

    <?php
    //Get an array of objects containing data for the current search/filter
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    var_dump($sf_current_query->get_array());
    ?>

    ERROR: Fatal error: Call to a member function get() on a non-object in …


    Anonymous
    Inactive

    THANK YOU so much Ross for helping with my prior questions that are now RESOLVED.

    Now I moved my Resources section that uses Search and Filter Pro live http://leadernet.org/featured-resources/ The search output goes to post type archive http://leadernet.org/resources/ .
    When no search is performed I need this archive page title to say “Showing results for all resources” vs YOU SEARCHED FOR: nothing

    I can’t figure it out.
    I can check for the length of of my text entry $my_search_term
    I’m lost trying to have an indicator of none of taxonomy checkboxes being selected.

    $my_search_term = $sf_current_query->get_search_term();
    $taxonomies = $sf_current_query->get_fields_html($fields, $args);
    echo “<br> search term length is” . strlen($my_search_term); — is 0 when none in text box
    echo “<br> term array length is” . count($taxonomies); — always 1 no matter selections

    What am I missing?

    Looking forward to your guidance, Nina

Viewing 10 results - 331 through 340 (of 344 total)