Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 341 through 350 (of 374 total)
  • Author
    Search Results
  • #46959

    Trevor
    Moderator

    OK

    I have re-written that a bit and added a new line after each line output. It may not work, but it is better code:

    <?php
      global $searchandfilter;
      $sf_current_query = $searchandfilter->get(2327)->current_query()->get_array();
      if (isset ($sf_current_query)) {
        foreach($sf_current_query as $key) {
          echo '<span class="results-term">' . $key['active_terms'][0]['name'] . '</span><br />';
        }
      }
    ?>
    #46958

    eli Shvrzman
    Participant
    This reply has been marked as private.
    #44951

    Trevor
    Moderator

    So, it is relatively simple if you are using the Shortcode Display Results method. See the documentation:

    http://www.designsandcode.com/documentation/search-filter-pro/search-results/using-a-shortcode/

    See how it is using a template called results.php?

    This is that file:

    <?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
     *
     */
    
    if ( $query->have_posts() )
    {
    	?>
    	
    	Found <?php echo $query->found_posts; ?> Results<br />
    	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( 'Older posts', $query->max_num_pages ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></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><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    			
    			<p><br /><?php the_excerpt(); ?><p>
    			<?php 
    				if ( has_post_thumbnail() ) {
    					echo '<p>';
    					the_post_thumbnail("small");
    					echo '</p>';
    				}
    			?>
    			<p><?php the_category(); ?><p>
    			<p><?php the_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( 'Older posts', $query->max_num_pages ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></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";
    }
    ?>

    And here is it modified:

    <?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
     *
     */
    
    if ( $query->have_posts() ) {
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(1526)->current_query();
    	if ($sf_current_query->is_filtered()) {
    		?>
    
    		Found <?php echo $query->found_posts; ?> Results<br/>
    		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('Older posts', $query->max_num_pages); ?></div>
    			<div class="nav-next"><?php previous_posts_link('Newer posts'); ?></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><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
    				<p><br/><?php the_excerpt(); ?><p>
    					<?php
    					if (has_post_thumbnail()) {
    						echo '<p>';
    						the_post_thumbnail("small");
    						echo '</p>';
    					}
    					?>
    				<p><?php the_category(); ?><p>
    				<p><?php the_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('Older posts', $query->max_num_pages); ?></div>
    			<div class="nav-next"><?php previous_posts_link('Newer posts'); ?></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";
    }
    ?>

    replace 1526 with the id of your search form.

    #43915

    Trevor
    Moderator

    Ok.

    So, this is the code I made:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    }

    If you wanted to put the X before each, replace the echo line with something like this:

    echo '<div><a id="executeMyCodeLink" href="#">X</a> ' . $key['active_terms'][0]['value'] . '</div>';
    

    Where the code to add to the page would be something like this

    <script>
      $('#executeMyCodeLink').click(function(event) {
        /// Your code here
      });
    </script>

    But that is beyond the scope of what I can do easily 🙁

    #43893

    Trevor
    Moderator

    So, one error on the page 🙁

    Line 26 should be this:

    if ( !$sf_current_query->is_filtered() ) {
    
    #43630

    cascadegroup
    Participant

    Thanks for this code, I had to adjust the code to add extra closing brackets for the STRING (below), unfortunately this results in the same data being given.

    “Yacht Length: 40-50m”

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query();
    echo $sf_current_query->get_field_string(“_sft_length”, array(“str” => “%2$s”));
    echo $sf_current_query->get_field_string(“_sft_rate”, array(“str” => “%2$s”));
    echo $sf_current_query->get_field_string(“_sft_guest”, array(“str” => “%2$s”));
    echo $sf_current_query->get_field_string(“_sft_location”, array(“str” => “%2$s”));
    echo $sf_current_query->get_field_string(“_sft_toy”, array(“str” => “%2$s”));
    ?>

    #43625

    Trevor
    Moderator

    Hi, can you try this code (it might be a step backwards, but bear with me):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query();
    echo $sf_current_query->get_field_string("_sft_length", array("str" => "%2$s");
    echo $sf_current_query->get_field_string("_sft_rate", array("str" => "%2$s");
    echo $sf_current_query->get_field_string("_sft_guest", array("str" => "%2$s");
    echo $sf_current_query->get_field_string("_sft_location", array("str" => "%2$s");
    echo $sf_current_query->get_field_string("_sft_toy", array("str" => "%2$s");
    #43565

    cascadegroup
    Participant

    Hi,

    I’ve added the code but it seems to be throwing an error on the array. Am I missing something?
    <?php
    //Get a multiple fields values by passing an array of field names
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query();
    echo $sf_current_query->get_fields_html(array(), array(‘show_all_if_empty’ => false)
    );
    ?>

    I’ve also added the code from the supplied link but it throws back the following error:
    array(2) { [“_sft_length”]=> array(5) { [“name”]=> string(13) “Yacht Lengths” [“singular_name”]=> string(12) “Yacht Length” [“all_items_label”]=> string(17) “All Yacht Lengths” [“type”]=> string(8) “taxonomy” [“active_terms”]=> array(1) { [0]=> array(4) { [“id”]=> int(6) [“name”]=> string(6) “40-50m” [“value”]=> string(6) “40-50m” [“count”]=> int(5) } } } [“_sft_toy”]=> array(5) { [“name”]=> string(15) “Yacht Hero Toys” [“singular_name”]=> string(14) “Yacht Hero Toy” [“all_items_label”]=> string(19) “All Yacht Hero Toys” [“type”]=> string(8) “taxonomy” [“active_terms”]=> array(1) { [0]=> array(4) { [“id”]=> int(16) [“name”]=> string(7) “Freezer” [“value”]=> string(7) “freezer” [“count”]=> int(5) } } } }

    Found on the same web link as before.

    #43320

    Ross
    Keymaster
    This reply has been marked as private.
    #42840

    Trevor
    Moderator

    Hi

    It should look like this a bit, I think:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();
    if ($sf_current_query->is_filtered()) {
    // do the loop
    } else {
    // do something else
    }
Viewing 10 results - 341 through 350 (of 374 total)