Forums Forums Search & Filter Pro How to not show results in first search + translate "Older/ newer posts"

Viewing 10 posts - 1 through 10 (of 20 total)
  • Anonymous
    #68154

    [thread split from https://support.searchandfilter.com/forums/topic/how-to-not-show-results-in-first-search-translate-older-newer-posts/ by @trevorsf ]

    Hi Trevor,

    I’ve attempted to use this code (and the solutions from the other threads without any luck at all). I don’t want to start another thread with the same question because you’ve had to repeat yourself a few times. Hopefully this is OK.

    I’m using the shortcode method for displaying my search and results. I tried the second piece of code from this thread: https://support.searchandfilter.com/forums/topic/how-do-i-hide-initial-results/page/2/#post-44951 but it displays all the items on load instead of hiding them until someone searches.

    In this example you have a ! in “if (!$sf_current_query->is_filtered()) {” and say nothing should go in the brackets before the else statement. I’ve added the output part of the results.php but I’m not have any success.

    Would it be possible to get an updated results.php example like you did in the other thread that will display nothing until the user searches and if they get no results it will display the message?

    Trevor
    #68157

    Something like this:

    <?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
     *
     */
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
    	
    	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";
    }
    }
    ?>

    I think?

    Anonymous
    #68159

    Thank you for the quick response!

    However, it’s still not working for me.

    http://brwbox.com/cms/test-page/

    10001 is a valid search but it still displays the “Nothing to see here folks!”

    Trevor
    #68161

    You substituted 25 for the 1726 in my example?

    Anonymous
    #68163

    Yes I did.

    Trevor
    #68171

    Wait, the URL is not updating. That means something is wrong in the form setup. Can you screen shot the first two form settings tabs (General and Display results)?

    Anonymous
    #68173

    Screen 1

    Screen 2

    Trevor
    #68178
    This reply has been marked as private.
    Anonymous
    #68180

    Sorry Trevor, I can’t read the private message because I didn’t start the thread.

    Anonymous
    #68194

    I had to swap out the theme and switch the site back on for the client. I’m still looking for a solution to this.

    The search functionality works great normally. It’s when I try to hide the initial search that it fails.

    http://brwbox.com/cms/ – Buy Online

Viewing 10 posts - 1 through 10 (of 20 total)