Support Forums

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

Forums Forums Search Search Results for 'found_posts'

Viewing 10 results - 181 through 190 (of 254 total)
  • Author
    Search Results
  • #95823

    Trevor
    Moderator

    Hi

    Thinking about this some more. In the WordPress Codex:

    https://codex.wordpress.org/Plugin_API/Filter_Reference/found_posts

    So that should give you what you the count that you want, yes? In a standard WordPress query, the query array is $wp_query, but your theme may have a customised version, but it should have the found_posts variable still.

    If you take a look at this part of our documentation, Ross has added some examples that you could use to get the search terms in the fields/taxonomies.

    https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/#Get_labelsfor_Multiple_Fields_by_Field_Name

    I think you should be able to use these examples to make your own code? The last example especially (for you).

    #95003

    BAM
    Participant

    Hi, I took the results.php template from a sample I found in this forum, and it has always given 3 columns instead of 4. You can view the search at the development location here. Here is the entire current results.php:

    <?php
    /**
     * Search & Filter Pro 
     *
     * Sample Results Template
     * 
     * @package   Search_Filter
     * @author    Ross Morsali
     * @link      http://www.designsandcode.com/
     * @copyright 2015 Designs & Code
     * 
     * Note: This template has been modified to link search results 
     * images to artist pages that need to be defined in 
     * Custom Fields in the individual image post. 
     * 
     * The custom field is “artistpage” . 
     * The image in search results will incorporate the link you set  
     * for that custom field. If no link is defined, the image will
     * not link to an artist page.
     *
     * 
     *
     */
    
    if ( $query->have_posts() )
    {
    	?>
    	
    	<div class="sixteen columns">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></div>
    	
    	<?php
    	$column_count = 0;
    	$last_class = "";
    	while ($query->have_posts())
    	{
    		$query->the_post();
    
    		if ($column_count == 0) echo '<div class="sixteen columns">';
    		?>
    		<div class="one_fourth<?php echo $last_class;?>">
    			
    		
    <?php
      if ( has_post_thumbnail() ) { ?>
        <span class="responsive"><a href="<?php echo get_post_meta($query->post->ID,'artistpage',true); ?>">
    <?php the_post_thumbnail("small");?></a></span>
      <?php	} ?>		
    		</div>
    		
    		<?php
    	 $column_count ++;
     if ($column_count == 4) {
    			$column_count = 0;
    			echo '</div>';
    			$last_class = "";
    		}
    if ($column_count == 3) {
    			$last_class = " last";
    		}
    
    				}
    
    	if ($column_count > 0) echo '</div>';
    	?>
    	<div class="sixteen columns">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></div>
    	<?php
    }
    else
    {
    	echo "No Results Found";
    }
    ?>

    Thank you for your help!

    #94405

    BAM
    Participant

    Hi, I am customizing the search results using some of the responses I found here, but I have a more specific request, and I’m having trouble finding the answer. Please let me know if it has already been asked.

    My search results are currently in a grid format showing the linked title and an unlinked thumbnail image. The linked title is linked to the project page (the_permalink). Full results.php below.

    I need to modify this so that the thumbnail image is linked, but it should be a link I can customize. I would like to customize the link using the Custom Fields when I create the project/post. For example, I would create a custom field called “artistpage” and define the link there. (Is this possible?)

    The end goal: Users search artist projects until they find what they like, then click the image to reach the artist page. The artist page contains many portfolio examples that appear within the search, plus biography, contact info, etc – it can’t be an individual image post. (I have considered a redirect from the project/post page, but I’d rather use a direct link if possible. In either case, I need help adding the link to the thumbnail image.)

    Thank you for your help and advice.

    Current results.php:

    <?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() )
    {
    	?>
    	
    	<div class="sixteen columns">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></div>
    	
    	<?php
    	$column_count = 0;
    	$last_class = "";
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		if ($column_count == 0) echo '<div class="sixteen columns">';
    		?>
    		<div class="one_fourth<?php echo $last_class;?>">
    			<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    			<p><br /><?php the_excerpt(); ?></p>
    			<?php 
    				if ( has_post_thumbnail() ) {
    					echo '<span class="responsive">';
    					the_post_thumbnail("small");
    					echo '</span>';
    				}
    			?>
    			<p><?php the_category(); ?></p>
    			<p><?php the_tags(); ?></p>
    			
    			
    		</div>
    		
    		<?php
    	 $column_count ++;
    		if ($column_count == 4) {
    			$column_count = 0;
    			echo '</div>';
    			$last_class = "";
    		}
    		if ($column_count == 3) {
    			$last_class = " last";
    		}
    	}
    	if ($column_count > 0) echo '</div>';
    	?>
    	<div class="sixteen columns">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></div>
    	<?php
    }
    else
    {
    	echo "No Results Found";
    }
    ?>
    #92230

    david jolly
    Participant

    Hi Trevor,

    In fact, i’ve a search.php file for my results. I wrote this code which appears on the top of the results :

    global $searchandfilter;
    global $post;
    	$author_id = $post->post_author;
    	$author = get_the_author_meta('display_name', $author_id);
    	$sf_current_query = $searchandfilter->get(802)->current_query();
    	$num_res = $wp_query->post_count;
    	echo $sf_current_query->get_field_string("_sft_category").'<br />';
    	echo $sf_current_query->get_field_string("_sft_thematique").'<br />';
            if($num_res == 0) {
    	echo 'Terme(s): '.$sf_current_query->get_search_term().'<br />';
    	}
    	echo 'El&eacute;ment(s) trouv&eacutes(s): ' .$wp_query->found_posts;

    I can display the author which is selected from the author select list but i don’t want to display anything if no author selected.

    I need a valid snippet which might be :

    if ($author_id != '0') {
    	echo $author.'<br />';
    	}

    Thank you for your help.

    Best regards.

    #91601

    david jolly
    Participant

    Hello Trevor,
    What i meant : You give some snippets to display some informations like thais :

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(802)->current_query();
    echo $sf_current_query->get_field_string("_sft_category").'<br />';
    echo $sf_current_query->get_field_string("_sft_thematique").'<br />';
    echo 'Terme(s): '.$sf_current_query->get_search_term().'<br />';
    echo 'El&eacute;ment(s) trouv&eacutes(s): ' .$wp_query->found_posts;

    I’d like to have a snippet to display the author chosen in my select list. If i try that code, it doesn’t work :

    echo $sf_current_query->get_field_string("authors");

    Is it possible to realize this ? It’s not in your documentation.

    Thank you for your help.

    Best regards.

    #91599

    Pierre
    Participant

    Yes this is resolved, all works like a charm.
    For my post results count I change args of my query like this:
    $args[‘search_filter_id’] = 77;
    $query = new WP_Query($args);

    $query->found_posts

    Thank you for your help.
    Best.
    Pierre

    #91473

    Top School
    Participant

    Ooops. I tried to create a code box with bbcode but it seems it doesn’t work here. Sorry for that! Here you have it again.

    <?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(21899)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div> </div>'; 
    } else {
    	
    	if ( $query->have_posts() )
    {
    	?>
    
    	Se han encontrado <strong><?php echo $query->found_posts; ?> resultados</strong><br />
    	
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    		<div class='search-filter-results-list'>
    			<a href="<?php the_permalink(); ?>"><h2 class='search-filter-title'><?php the_title(); ?></h2>
    		
    			<?php 
    				if ( has_post_thumbnail() ) {
    					echo '<div class="menu-img">';
    					the_post_thumbnail("full");
    					echo '</div>';
    				}
    			?>			
    		</a></div>
    		
    		<?php
    	}
    	?>
    	<?php
    }
    else
    {
    	echo "No se han encontrado resultados";
    }
    }
    ?>
    #91472

    Top School
    Participant

    Thank you very much for such a nice plugin. It works like charm and we are very happy with it! Up until now we have managed to sort out all the little problems we’ve had by reading the forum, but I can’t find a solution to this one.

    I have added a “Search field” to my form and, whenever I deliberately look for a term that doesn’t exist, instead of displaying the “No results found” message, it returns all the items unfiltered. Is there a way to solve this?

    It may have something to do with my results .php, which I have edited quite a bit, but I’m not sure. This is the code I’m using for it:

    [code]
    <?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(21899)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) {
    echo ‘<div> </div>’;
    } else {

    if ( $query->have_posts() )
    {
    ?>

    Se han encontrado <?php echo $query->found_posts; ?> resultados<br />

    <?php
    while ($query->have_posts())
    {
    $query->the_post();

    ?>
    <div class=’search-filter-results-list’>
    “><h2 class=’search-filter-title’><?php the_title(); ?></h2>

    <?php
    if ( has_post_thumbnail() ) {
    echo ‘<div class=”menu-img”>’;
    the_post_thumbnail(“full”);
    echo ‘</div>’;
    }
    ?>
    </div>

    <?php
    }
    ?>
    <?php
    }
    else
    {
    echo “No se han encontrado resultados”;
    }
    }
    ?>
    [/code]

    #89027

    Kristin Snelling
    Participant

    I have poked around the forums and documentation to try to find an answer to this, but could not find anything – please direct me to and former posts that I have overlooked!

    I have the Search & Filter Pro plugin set up, and have a search form set up that loads results with ajax. I am using the shortcode method, so I have the form shortcode in a sidebar widget, and the results shortcode in the body of my page. Everything works great, I really like this plugin!

    I am overriding results.php in my_theme/search-filter/results.php which works. The theme I am using is a child of _tk (by theme kraft). The theme has its own bootstrap numeric pagination function built in, which works great on my regular site search results page (using the theme’s search.php template), but when I attempt to call that function into the results.php template, nothing shows up. Here is my code in results.php:

    if ( $query->have_posts() )
    {
    	?>
    	Found <?php echo $query->found_posts; ?> Results <br/>
    	<?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>';
    				}
    			?>		
    		</div>
    		
    		<hr />
    		<?php
    	}
    	?>
    	Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
    	<div class="pagination">
    		<div class="numeric"><?php _tk_pagination($query->max_num_pages); ?
    	</div>
    
    	<?php
    }
    else
    {
    	echo "No Results Found";
    }

    Any thoughts on why this might not be working? I can provide the url if that is needed. I can also provide the theme’s pagination function code if that is needed.

    #87657

    In reply to: Force selection?


    Trevor
    Moderator

    Hi Lisa

    You can also let them search, but show them nothing (or a custom message) using this type of PHP code (change the number 1234 for the ID number of your search form and change the line echo '<div>Nothing to see here folks!</div>'; for whatever you want before the filter is used instead of the results – or remove for nothing at all):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1234)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your theme template code here for the part that runs the loop, e.g. if ( $query->have_posts() ) .....
    }

    For example, if you were using the shortcode method. OK, if you have followed the documentation to make a copy of the results.php into a new folder called search-filter in your child theme or theme folder, then replace the contents of that template file with 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(1234)->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";
    }
    }
    ?>
Viewing 10 results - 181 through 190 (of 254 total)