Forums Forums Search Search Results for 'active_terms 0 name'

Viewing 10 results - 1 through 10 (of 45 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.

    #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";
    }
    ?>
    #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>
    #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");
    	
    ?>
    #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”);

    ?>

Viewing 10 results - 1 through 10 (of 45 total)