Search Results for 'active_terms 0 name'

Forums › Forums › Search › Search Results for 'active_terms 0 name'

Viewing 10 results – 1 through 10 (of 51 total)
  • Author
    Search Results
  • #259956

    Anonymous
    Inactive

    Hi Trevor,
    Thank you for the response. The code you sent works well, however, it needs to be in the archive page itself to work, which is something I’m trying to avoid because that would mean the page has to reload to display the active filters.

    I tried to run it through AJAX once the form submits. But I’m not getting any results. (below is the function I added to functions.php) (the ajax request works fine, so the issue is with $searchandfilter).

    Is there any way to use the “$searchandfilter” class and the “current_query()” method from OUTSIDE the archive page?

    Please let me know. thank you.

    add_action( 'wp_ajax_show_active_filters',  'show_active_filters' );
    add_action( 'wp_ajax_nopriv_show_active_filters', 'show_active_filters' );
    function show_active_filters(){
        global $searchandfilter;
        $sf_current_query = $searchandfilter->get(8175)->current_query()->get_array();
        ob_start();
        
        echo '<span class="active-pill">'.$sf_current_query['_sft_contest-years']['active_terms'][0]['name'].'</span>';
    
        $ajax_filters_html .= ob_get_contents();
        ob_end_clean();
        echo json_encode(array('html'=>$ajax_filters_html));
        wp_die();
    }
    #253147

    Trevor
    Participant

    The code you would need is:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(9490)->current_query()->get_array();
    echo $sf_current_query['_sfm_UnitLocation']['active_terms'][0]['name'];

    Look carefully, as only the ‘global’ line is the same.

    Note, if you are using Ajax on the page, you may need to make sure that the page title is inside the Ajax Container, otherwise it will not refresh and change.


    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!

    #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>
    #250744

    Trevor
    Participant

    This post should help you:

    https://support.searchandfilter.com/forums/topic/acf-post-meta-fields-in-current_query-result/#post-249704

    Or other posts from this search (some will be private, so those you cannot see, sorry):

    https://support.searchandfilter.com/forums/search/active_terms+0+name/

    #249704

    Trevor
    Participant

    You first need to find out where the data is, and to do so you need to examine the filter array:

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

    This will print that array to the screen. From that you would need to use code LIKE this:

    echo $sf_current_query['_sft_category']['active_terms'][0]['name']

    This would echo out the first Category term. You will need to write a similar line, for example:

    echo $sf_current_query['_sfm_industries']['active_terms'][0]['name']

    #246960

    Trevor
    Participant

    I have edited and tested it for you. This is the code I used in the end:

    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(1949)->current_query()->get_array();
    	$category = $sf_current_query['_sft_category']['active_terms'][0]["name"];
    	$county = $sf_current_query["_sfm_county"]["active_terms"][0]["name"];
    	if ($category) {
    		echo $category . ", ";
    	} else {
    		echo "All Categories, ";
    	}
    	if ($county) {
    		echo $county;
    	} else {
    		echo "All Counties";
    	}

    You may edit that to make it look better though.

    #246641

    Anonymous
    Inactive

    I do, thanks. However, it’s now outputting the text ‘ArrayAntigonish’ (or ‘Array’ + whatever county is selected) and it’s not outputting category name. I have tried to puzzle through this to see if I can work out how to fix it myself but my PHP just isn’t good enough.

    Here’s a link to a sample results page.

    What I’d like it to say is something like “You searched for Breweries, Distilleries, and Vineyards in Antigonish County” and then the results.

    Below is the full code of results.php. If you can offer any more insight I’d be grateful.

    <?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
     *
     */
    
    // If this file is called directly, abort.
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    if ( $query->have_posts() )
    {
    	?>
    	
    	There are <?php echo $query->found_posts; ?> posts that match your search! <br />
    
    	<?php
    	
    	 global $searchandfilter;
    	 
    $sf_current_query = $searchandfilter->get(1949)->current_query()->get_array();
    
    echo implode(", ",$sf_current_query['_sft_category']['active_terms']);
    $county = $sf_current_query["_sfm_county"]["active_terms"][0]["value"];
    if ($county) {
    echo $county;
    } else {
    echo "All Counties";
    }
    	
    
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    		<div>
    			<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    			
    			<p><?php the_excerpt(); ?></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( 'Next page', $query->max_num_pages ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( 'Previous page' ); ?></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";
    }
    ?>

    Anonymous
    Inactive

    Hi, I am using your (terrific) plugin with Elementor Pro. I am having quite a hard time displaying a headline with the chosen custom categories above my search results. I mean: Search results for taxonomy a1, taxonomy a2, taxonomy b and taxonomy c.

    I found your post:
    https://support.searchandfilter.com/forums/topic/results-displayed-results-count-searched-tag-associated-categories/

    and adapted it for my use. It turned out quite well BUT this headline does not change when I select another filter. Can you think of any solution for this?

    My code:

    <?php
      global $searchandfilter;
      $sf_query = $searchandfilter->get(5360)->current_query();
      if ($sf_query->is_filtered()) {
        $sf_current_query = $searchandfilter->get(5360)->current_query()->get_array();
        echo "<b>Onderzoek met betrekking tot ";
        $cat_string = "";
        foreach($sf_current_query['_sft_category']['active_terms'] as $item) {
          $cat_string .= $item['name'] . ", ";
        }
        $starost_string = "";
        foreach($sf_current_query['_sfm_starost']['active_terms'] as $item) {
          $starost_string .= $item['name'] . ", ";
        }
    if (($sf_current_query['_sft_reflex-categorie']['active_terms'][0]['name'])<>"") echo "<p>" . ($sf_current_query['_sft_reflex-categorie']['active_terms'][0]['name']) . "</p>";
    if (($sf_current_query['_sft_vaardigheden-categorie']['active_terms'][0]['name'])<>"") echo "<p>" . ($sf_current_query['_sft_vaardigheden-categorie']['active_terms'][0]['name']) . "</p>";
    if (($sf_current_query['_sft_diagnose-categorie']['active_terms'][0]['name'])<>"") echo "<p>" . ($sf_current_query['_sft_diagnose-categorie']['active_terms'][0]['name']) . "</p>";
    echo "</b>";
    }
    ?>

    My CSS:

    p {
    margin: 0;
    display: inline;
    }

    p:not(:last-child)::after { content: ” & “; }
    p:last-child::after { content: “”; }

    Thank you so much in advance!
    Monique

    #238475

    Trevor
    Participant

    So, here is a search:

    _sft_location=cotswolds
    _sft_partysize=ten-guests
    _sft_features=garden-patio,internet

    The code I added was this (replace the 12345 with your form ID):

    <div>
      <?php
      global $searchandfilter;
      $sf_current_query = $searchandfilter->get(12345)->current_query()->get_array();
      $locations_filter = $sf_current_query["_sft_location"]["active_terms"][0]["name"];
      if ( $locations_filter <> "") {
        echo '<div>Location: ' . $locations_filter . '</div>';
      }
      $party_size_filter = $sf_current_query["_sft_partysize"]["active_terms"][0]["name"];
      if ( $party_size_filter <> "") {
        echo '<div>Guests: ' . $party_size_filter . '</div>';
      }
      $features_filter_array = $sf_current_query["_sft_features"]["active_terms"];
      if ( $features_filter_array ) {
        echo '<div>Features: ';
        foreach($features_filter_array as $value) {
          $features_list .= $value["name"] . ", ";
        }
        echo rtrim($features_list, ", ") . '</div>';
        }
      ?>
    </div>
Viewing 10 results – 1 through 10 (of 51 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.