Forums Forums Search Search Results for 'sf_current_query'

Viewing 10 results - 291 through 300 (of 318 total)
  • Author
    Search Results
  • #44951

    Trevor
    Participant

    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
    Participant

    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
    Participant

    So, one error on the page 🙁

    Line 26 should be this:

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

    Anonymous
    Inactive

    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
    Participant

    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

    Anonymous
    Inactive

    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.

    #42840

    Trevor
    Participant

    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
    }
    #42786

    Anonymous
    Inactive

    Thanks Trevor!
    I am using a theme I started from underscores template

    Installed the results.php template and I am trying to use the github code here as reference.
    but no luck yet..

    Any chance you can guide me a bit further?

    Where do I place the following code in my results.php if it needs to be before the “have_posts” loop?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();
    echo $sf_current_query->is_filtered();
    #41768

    Ross
    Keymaster

    Hi Adam

    S&F doesn’t search tag names, nor does the default WP search – try your “Flowers” test with the old search and you will see (you can search tag names by combining S&F with Relevanssi).

    RE the input box, thats the last step we missed!

    So, each of the search input fields, that you have changed to be renamed to _sf_s, also has a value attribute.

    <input type="text" placeholder="<?php _e( 'Search', 'squarecode' ); ?>" value="<?php echo $searchresults; ?>" name="_sf_s" id="s" />

    we need to get the S&F search term into this value attribute. I can see in both your header and search templates, that the query is populated with the value from this line:

    <?php $searchresults = get_search_query(); ?>

    So all we need to do is get S&F search query into that variable – from the docs you would replace the code above with –

    <?php
    	//Get the search term
    	//replace <code>4243</code> with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(4243)->current_query();
    	$searchresults = $sf_current_query->get_search_term();
    ?>

    Thanks

    #39703

    Anonymous
    Inactive

    I finally found this solution:

    $sarr = $sf_current_query->get_array();

    $author = $sarr[authors][active_terms][0][name] ;
    $fromDate = $sarr[_sf_post_date][active_terms][0][value] ;
    $toDate = $sarr[_sf_post_date][active_terms][1][value];

    I hope it keeps on working always!

Viewing 10 results - 291 through 300 (of 318 total)