Forums Forums Search Search Results for 'sf_current_query'

Viewing 10 results - 91 through 100 (of 318 total)
  • Author
    Search Results
  • #223272

    Trevor
    Participant

    Such functionality would be within the scope of the theme and the template in use. Other than when the shortcode method is being used, our plugin has no direct control over your required behavior.

    The coding required would look something like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(85204)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your current results template code here
    }

    Where the ID number (85204) would need to be whatever ID number your form is.

    #223002

    Trevor
    Participant

    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 could temporarily use this code in your results template to display the full filter array so that you can work out the exact array part that holds the data you want:

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

    Where the ID needs to match that of your form.

    #222988

    Anonymous
    Inactive

    I want to do some custom formatting depending on the used filters… I tried this:
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(69991)->current_query();
    echo $sf_current_query->get_fields_html(
    array(“_sfm_mk_quelle_affiliate_shop”),
    $args
    );

    … and: echo $sf_current_query->get_field_string(“_sfm_mk_quelle_affiliate_shop”);

    And took the field name from my search url:
    https://miriamkreativ.de/material?_sfm_mk_quelle_affiliate_shop=Creativ-Discount

    But there is nothing shown unfortunately…

    I tried one more thing (displaying the searchg term):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(69991)->current_query();
    echo $sf_current_query->get_search_term();

    … and this works for me. So please can you help me with the first example, showing / getting the chosen “affiliate shop”-option?

    #222869

    Trevor
    Participant

    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 could use this to display the filter array:

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

    Where the ID needs to match that of your form.


    Trevor
    Participant

    That will be a function from your theme to see if a standard WordPress text search has been made, which indeed would be required to remove. Make sure you are using a child theme and name this file differently, and point our search to use this new file as the template.

    Our plugin, if you want to make a similar check if a search has been made, would use code like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(85204)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your current results template code here
    }

    Where the IF condition is set to display a different message if no search has been made (you can obviously change what it says, including adding HTML etc). Laos, change the ID number 85204 to whatever ID number our form is.

    #220260

    Anonymous
    Inactive

    Yes,

    I’m trying to figure it out. But all what I try it also removes the term.

    Like, if it is “activity: ski jobs” it ends with “jobs”

    Using this code:

    <?php echo $sf_current_query->get_field_string(“_sft_activities”); ?> jobs

    Thank you in advance!

    #220252

    Anonymous
    Inactive

    Ok got it:

    <?php echo $sf_current_query->get_field_string(“_sft_activities”); ?> jobs

    But it displays like this activities: ski jobs

    How can I remove the “activities:”

    Thanks again for your time!

    #220250

    Anonymous
    Inactive

    Thanks for the response.

    I’ve done that but it doesn’t work:

    <?php
    //grab the active query from our search form
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(3959)->current_query();
    ?>
    <h1 class=”hjobs”><?php echo $sf_current_query; ?> jobs</h1><br>

    What am I doing wrong?

    Thanks!

    #220031

    Trevor
    Participant

    From your original code I would have had this:

    <?php
    /**
     * Search & Filter Pro 
     *
     * Sample Results Template
     * 
     * @package   Search_Filter
     * @author    Ross Morsali
     * @link      http://www.designsandcode.com/
     * @copyright 2015 Designs & Code
     * 
     * Note: these templates are not full page templates, rather 
     * just an encaspulation of the your results loop which should
     * be inserted in to other pages by using a shortcode - think 
     * of it as a template part
     * 
     * This template is an absolute base example showing you what
     * you can do, for more customisation see the WordPress docs 
     * and using template tags - 
     * 
     * http://codex.wordpress.org/Template_Tags
     *
     */
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(233)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
    if ( $query->have_posts() )
    {
    	?>
          
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    	
    	    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		    <a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>">
    		        <h2><?php the_title(); ?></h2>
                    <?php if( get_field('summary_portfolio_description') ): ?>
                        <p><?php the_field('summary_portfolio_description'); ?></p> 
                    <?php endif; ?>		        
    		       <?php the_excerpt(); ?>
                </a>
            </article>
            
    		<?php
    	}
    
    }
    else
    {
    	echo "<span id='no-results'>No results found, please try altering your search criteria.</span>";
    }
    }
    ?>
    #219973

    Anonymous
    Inactive

    Hi Trevor,

    Thanks for the prompt reply, I’ve amended my results.php file as per your suggestion on that other post but I think I’ve done something wrong as no results show now.

    This is my code:

    if ( $query->have_posts() )
    {
    	?>
          
    	<?php
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(233)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
         
            
    		?>
    	
    	  Results code here.
            
    		<?php} 
    	}
    
    ?>

    Any ideas where I’m going wrong with this?

    Thanks,

    James

Viewing 10 results - 91 through 100 (of 318 total)