Search Results for 'sf_current_query'

Forums › Forums › Search › Search Results for 'sf_current_query'

Viewing 10 results – 41 through 50 (of 357 total)
  • Author
    Search Results

  • Trevor
    Participant

    Having said that, you might be able to do it using this filter:

    https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object

    … where the PHP would first have to check to see if a search has been done, and then conditionally remove the numbers in brackets from the labels. But that might slow things down a little.

    The general method to detect if a search has been made is this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // code here to remove the counts
    }

    Replace the ID number with that of your form.

    As the count is always in brackets, you could find the position of the last instance of ( in the string, and trim the string to that left most number of characters of the string (minus 1 I think, as there will be a space also).


    Anonymous
    Inactive

    Hi Trevor,

    I have some questions regarding the usage and hope you can help me.

    1. A drop down filter with custom ACF field. I have a front-end form created with ACF where one of the fields is Price. I have created a main filter where i use the range field with two values minimum price and maximum price and it works great. Now i am looking to create another small drop down filter with two options: Sort posts by lowest price and Sort posts by highest price. Sorry if it is obvious, but i could not find how can i achieve it using one single ACF field.

    2. The reset button does not work when filter is not submitted with AJAX. Is it how it should behave or am i missing something?

    3. Last thing, and perhaps it is a feature request. Would it be possible to make echoed filter labels clickable, so that each label resets/clears the corresponding filter input?

    I echo the filters labels using this method:

    
    global $searchandfilter;
    
    $sf_current_query = $searchandfilter->get(15197)->current_query()->get_array();
    
    if( isset( $sf_current_query['_sfm_watch_year']['active_terms'] ) ) :
    
            $get_years = $sf_current_query['_sfm_watch_year']['active_terms'];
    
            $show_year = '';
    
            if ( $get_years ) {
    
                foreach( $get_years as $value ) {
                    $show_year .= '<span class="fl">' . $value['name'] . '</span>';
                }
    
                $label_year = 'Years: ' . rtrim( $show_year, ', ' );
    
            }
    
        endif;

    This code show the labels of years checked checkboxes. What i mean is that years label will have a link and the click event will reset the years filter checkbox.

    Please see an example

    Thank you!

    #252346

    Trevor
    Participant

    Does that page use a PHP template file? If it does, using a child theme and a copy of that file in the child theme folder, edit that file to place logic like this in to it:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->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 products output code here
    }

    The ID number must match that of your form.

    Note, if you are using a page builder, this method may not be possible.

    #251712

    Trevor
    Participant

    More complex is needed then.

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query()->get_array();
    $search_cat = $sf_current_query['_sft_category']['active_terms'][0]['name'];
    ?>
    <header class="searсh-header">
    <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_cat;?></span></h1></header>
    #251704

    Trevor
    Participant

    Ah, sorry, I just realized, you want the category to show, NOT the search term?

    That may be a little more complex. This MIGHT work:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    $search_cat = $sf_current_query->get_field_string("_sft_category");
    ?>
    <header class="searсh-header">
    <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_cat;?></span></h1></header>
    #251679

    Trevor
    Participant

    You will need to replace 1234 with your form ID.

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    $search_term = $sf_current_query->get_search_term();
    ?>
    <header class="searсh-header">
    <h1 class="page-title">Résultats de la recherche : <span><?php echo $search_term;?></span></h1></header>

    See if that works?

    #251257

    Trevor
    Participant

    Something like this would do I think (change the ID number to suit):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // show normal loop
    } else {
      // show loop when S&F active
    }
    #251095

    Trevor
    Participant

    Ah, I see. I do not know of a way to do what you want. It would likely mean some advanced custom PHP coding using this filter (used in the child theme functions.php file):

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    You would first have to detect if any query had been set, possibly using code like this (but it may have to be modified):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // modify the query to place the desired posts first
    }

    You would need the services of a skilled coder I would think.


    Anonymous
    Inactive

    This strikes me as an easy fix but i’m just not finding the method –

    I’m writing a filter results page title like so:

    <h1 class="entry-title"><?php echo $sf_current_query->get_field_string("_sft_rugtype"); ?></h1>

    with _sft_rugtype (aka, Rug Type:) being the taxonomy we’re filtering by, this all works fine but the title gets printed as “Rug Type: [term name]” – we’re looking to exclude the taxonomy in the display so it only says the term name. My apologies if this is documented somewhere i’m struggling to find it.

    #250548

    Anonymous
    Inactive

    Hi Trevor thank you for the help- I tried adding the code to the top and replacing and it did not sort the tags alpahbetically. Where I am trying to accomplish this is the left side “Tags” filter on the resources page (https://hceg.org/resources/) before and after filtering.

    Here is the current code I updated on the search-filter/results.php file

    <?php
    /**
    * Search & Filter Pro
    *
    * Sample Results Template
    *
    * @package Search_Filter
    * @author Ross Morsali
    * @link https://searchandfilter.com
    * @copyright 2018 Search & Filter
    *
    * 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
    *
    */

    function compare_tags_naturally($a, $b) {
    return strnatcmp($a->name, $b->name);
    }
    if ( $query->have_posts() )
    {
    ?>

    <div style=”text-align: right”>
    <?php global $searchandfilter;
    $sf_current_query = $searchandfilter->get(13622)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) { } else { ?>
    Found <?php echo $query->found_posts; ?> Results,
    <?php } ?>
    Page <?php echo $query->query[‘paged’]; ?> of <?php echo $query->max_num_pages; ?></div>

    <div class=”pagination”>

    <div class=”nav-previous”><?php next_posts_link( ‘Previous’, $query->max_num_pages ); ?></div>
    <div class=”nav-next”><?php previous_posts_link( ‘Next’ ); ?></div>
    <?php
    /* example code for using the wp_pagenavi plugin */
    if (function_exists(‘wp_pagenavi’))
    {
    echo “<br />”;
    wp_pagenavi( array( ‘query’ => $query ) );
    }
    ?>
    </div>

    <?php
    while ($query->have_posts())
    {
    $query->the_post();

    ?>
    <div>
    <h2>” target=”_blank” class=”read_more_link”><?php the_title(); ?></h2>

    <?php the_excerpt(); ?>
    <?php
    if ( has_post_thumbnail() ) {
    echo ‘<p>’;
    the_post_thumbnail(“small”);
    echo ‘</p>’;
    }
    ?>
    <p><?php the_category(); ?></p>
    <?php
    $unsorted_tags = get_the_tags();
    $tags = usort($unsorted_tags, ‘compare_tags_naturally’);
    ?>
    <p><?php echo implode(‘, ‘, $tags); ?></p>
    <p><small><?php the_date(); ?></small></p>

    </div>

    <hr />
    <?php
    }
    ?>
    Page <?php echo $query->query[‘paged’]; ?> of <?php echo $query->max_num_pages; ?><br />

    <div class=”pagination”>

    <div class=”nav-previous”><?php next_posts_link( ‘Previous’, $query->max_num_pages ); ?></div>
    <div class=”nav-next”><?php previous_posts_link( ‘Next’ ); ?></div>
    <?php
    /* example code for using the wp_pagenavi plugin */
    if (function_exists(‘wp_pagenavi’))
    {
    echo “<br />”;
    wp_pagenavi( array( ‘query’ => $query ) );
    }
    ?>
    </div>
    <?php
    }
    else
    {
    echo “No Results Found”;
    }
    ?>

Viewing 10 results – 41 through 50 (of 357 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.