Forums Forums Search Search Results for 'found_posts'

Viewing 10 results - 71 through 80 (of 174 total)
  • Author
    Search Results
  • #188335

    Anonymous
    Inactive
    <?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 ( $query->have_posts() )
    {
    	?>
    	<div class="results-found">
    	Found <?php echo $query->found_posts; ?> Results<br /></div>
    	<div class='search-filter-results-list'>
    	<?php
    		while ($query->have_posts())
    		{
    			$query->the_post();
    			
    			?>
    			<div class='search-filter-result-item'>
    				
    				<?php 
    					if ( has_post_thumbnail() ) {
    						echo '<p>';
    						the_post_thumbnail("small");
    						echo '</p>';
    					}
    				?>
    				<h2><a href="<?php the_permalink(); ?>",><?php the_title(); ?></a></h2>
    						
    				</div>
    			
    			<?php
    		}
    	?>
    	</div>
    <?php
    }
    else
    {
    	?>
    	<div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
    		<span>End of Results</span>
    	</div>
    	<?php
    }
    ?>
    
    #188296

    Trevor
    Participant

    To the error; if it only randomly happens, it will be hard to track down, but my first though is that it must be something to do with these settings:

    https://www.screencast.com/t/EoLysM5EqD

    Maybe try changing what they are currently set at?

    Assuming you are using the Shortcode Display Results method:

    https://searchandfilter.com/documentation/search-results/using-a-shortcode/

    If so, I assume you copied the results-infinite-scroll.php template instead of the results.php template when you followed the customising guide there? It still needs to be named results.php in the child theme, so it would need renaming. It looks like this by default:

    <?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 />
    	<div class='search-filter-results-list'>
    	<?php
    		while ($query->have_posts())
    		{
    			$query->the_post();
    			
    			?>
    			<div class='search-filter-result-item'>
    				<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>
    				
    				<hr />
    			</div>
    			
    			<?php
    		}
    	?>
    	</div>
    <?php
    }
    else
    {
    	?>
    	<div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
    		<span>End of Results</span>
    	</div>
    	<?php
    }
    ?>

    On line 29 is this:

    Found <?php echo $query->found_posts; ?> Results<br />

    Simply delete that line and save.

    As to the loading icon, this thread might help:

    https://support.searchandfilter.com/forums/topic/search-filter-scroll-loading-icon-positionning-in-infinite-scroll/


    Anonymous
    Inactive

    That’s all working. Great. Thanks!

    Now I’d like to try to make it work with Ajax. All my settings are the same as above except I’ve selected the Authors post type and unselected Posts.

    When I select Load results using Ajax, then the filter doesn’t work.

    I’m doing all this on a page with the following content:

    [searchandfilter id="154"]
    
    [searchandfilter id="154" show="results"]

    And this page uses this custom template, which queries the db to get category names, then within each category queries to get posts. FYI each post can only have one category. Otherwise I’m aware that a given post could show up more than once on the page.:

    <?php
    /* template name: Authors Page */
     ?>
    <?php get_header(); ?>
     <div id="layout" class="pagewidth clearfix">
         <div id="content" class="authors-page clearfix">
        <?php
        //echo do_shortcode('[searchandfilter id="154"]');
        // get all the categories from the database
        $cats = get_categories(); 
    	// loop through the categries
    	foreach ($cats as $cat) 
    		{
    		// setup the cateogory ID
    		$cat_id= $cat->term_id;            // create a custom wordpress query
    		$args = array('post_type' => 'authors', 'cat' => $cat_id, 'meta_key' => 'author_last_name', 'orderby' => 'meta_value', 'order' => 'asc');
    		$args['search_filter_id'] = 154;
    		$query = new WP_Query($args);
    		$count = $query->found_posts;
    		if($count > 0) //fix this to test if there are any results (numrows > 0)
    			{
    			// Make a header for the cateogry
    			echo "<h2 class=\"category-name background\" style=\"clear:both\"><span>".$cat->name."</span></h2>";
    			}
    ?>
                        
         <div id="loops-wrapper" class="loops-wrapper sidebar1 grid3  boxed masonry infinite masonry-done blog" style="position: relative; height: 640.234px;">
         <div class="grid-sizer"></div>
         <div class="gutter-sizer"></div>
        <?php
        // start the wordpress loop!
     	if ( $query->have_posts() ) : ?>
    		<?php while ( $query->have_posts() ) : $query->the_post(); ?>	
    			<article id="post-<?php echo get_the_ID();?>" class="post clearfix post-<?php echo get_the_ID();?> type-post status-publish format-standard has-post-thumbnail hentry category-featured-authors has-post-title no-post-date " style="position: absolute; left: 0px; top: 500px;">
    			 <figure class="post-image  clearfix">
    				<a href="<?php the_permalink();?>"><img src="<?php echo get_the_post_thumbnail_url(); ?>" class=" wp-post-image wp-image-84" alt="<?php the_title(); ?>" srcset="" sizes="(max-width: 200px) 100vw, 200px" width="200" height="150"><img src="<?php the_field('featured_book_cover_image'); ?>" class="featured_title_cover_image" width="100" height="150"></a>
    				<a href="<?php echo esc_url( get_permalink() ); ?>" class="overlay">
    				<div class="excerpt-text"><?php the_field('mini_blurb'); ?></div>
    				</a>
    			  </figure>
    			  <div class="post-content">
    				<div class="post-content-inner">
    				<!-----------------ICON----------------->
    					<!--<span class="<?php if($on_list) { echo $icon_class; } ?> tooltips author-tooltips add_<?php echo get_the_ID();?> list-icon"  title="<?php echo $element_title; ?>">
    						<?php if(!$on_list) { ?><a href="#" class="<?php echo $icon_class; ?> btnAddAction" onclick = "cartAction('<?php echo $action; ?>','<?php echo get_the_ID();?>')"></a> <?php } ?>
    					</span>	-->
    				   <!-----------------/.ICON------------------>
    					<h2 class="post-title entry-title"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
    					<div class="entry-content">
    					   <?php the_field('featured_book_title'); ?>
    					</div><!-- /.entry-content -->
    				</div><!-- /.post-content-inner -->
    			  </div><!-- /.post-content -->
    		 </article>
    		<?php endwhile; wp_reset_postdata(); ?>
    		<!-- show pagination here -->
    	<?php else : ?>
    		<!-- show 404 error here -->
    	<?php endif; ?>
        </div><!-- #loops-wrapper -->
    <?php } // done the foreach statement ?>
    
    	</div><!-- #content -->
    </div><!-- #layout -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    This all works fine, except when I set it to use Ajax.

    Thanks.

    #181593

    Ross
    Keymaster

    Hi Tom

    How are you trying to do this?

    In WP, the variable is always in the query (if your display results method is set to shortcode, this will need adapting, let me know):

    global $wp_query;
    echo $wp_query->found_posts

    So you would need to add this in to your template, inside the Ajax Area.

    If I am following right though, you would like to display this data outside of the Ajax Area?

    In this case, the best thing to do would be to add a hidden element inside the ajax area:

    <input type="hidden" value="<?php echo $found_posts; ?>" id="my-found-posts" />

    Then with JavaScript, when you have new results loaded with Ajax, you find this variable and append it to the page somewhere.

    Take a look at the event sf:ajaxfinish which would be the right time to get this variable:
    https://searchandfilter.com/documentation/faq/#will-my-lightbox-or-other-fancy-javascript-work-with-this-plugin

    Let me know if that makes sense, and if I’ve jumped the gun here!

    Thanks

    #180335

    Trevor
    Participant

    This is our standard infinite scroll results.php template modified to have a no results message. Use this as a starting point:

    <?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 />
     <div class='search-filter-results-list'>
     <?php
      while ($query->have_posts())
      {
       $query->the_post();
       
       ?>
       <div class='search-filter-result-item'>
        <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>
        
        <hr />
       </div>
       
       <?php
      }
     ?>
     </div>
    <?php
    } else {
     
     //figure out which type of "no results" message to show
     $message = "noresults"; 
     if(isset($query->query['paged'])) {  
      if($query->query['paged']>1){
       $message = "endofresults";
      }
     }
     
        if($message=="noresults") {
        ?>
     <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
      <span>No Results Found</span>
     </div>
     <?php
        } else {
     ?>
     <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
      <span>End of Results</span>
     </div>
     <?php
     }
    }
    ?>

    Anonymous
    Inactive

    How can I set up a custom message when search returns 0 results?

    Site: Click here

    My code:

    <?php
    
    global $searchandfilter;
    
    $atrair_home = $searchandfilter->get(180)->current_query();
    
        if ((!$atrair_home->is_filtered())&&($atrair_home->get_search_term()=="")) {
    
            $args = array(
                'post_type' => array(
                    'post',
                    'ebooks',
                    'podcasts',
                    'videos'
                ),
                'post_status' => 'publish',
               );
               
              $posts = new WP_Query( $args );
              if( $posts->have_posts() ) :
              ?>
        <?php
                    while( $posts->have_posts() ) :
                      $posts->the_post();
                      ?>
            <div class="posts-double">
    				<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
    				<a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark">
    					<?php 
    										$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
    										echo '<div class="image" style="background:url('.esc_url($featured_img_url).')"></div>' ?>
    					<?php endif; ?>
    				</a>
    				<div class="content">
    					<a class="title" href="<?php the_permalink() ?>" rel="bookmark">
    						<?php the_title(); ?>
    					</a>
    					<p class="descriptions">
    						<?php echo wp_trim_words( get_the_content(), 15, '...' );?>
    					</p>
    					<div class="related-post-category">
    						<?php the_tags(); 
    								$post_type = get_post_type(get_the_ID());
    								$post_name = get_post_type_object(get_post_type())->labels;
    								if ( $post_type != 'post' ) {
    									echo '<a href="'.get_post_type_archive_link( $post_type ).'"><span class="'.$post_type.'">'.$post_name->name.'</span></a>';
    								};
    								?>
    					</div>
    				</div>
    				<div class="posts-footer">
    						<div class="related-time">
    							<?php echo do_shortcode('[rt_reading_time]'); ?>
    						</div>
    						<div class="related-bookmark">
    							<?php echo do_shortcode('[cbxwpbookmarkbtn]'); ?>
    						</div>
    					</div>
    			</div>
            <?php
                    endwhile;
                    wp_reset_postdata();
        
              else :
                echo 'Não conseguimos encontrar nenhum resultado...';
              endif;
        
                }
    
        else
        //Inicio fim
        {
    
            if ( $query->have_posts() )
            {
                ?>
                
                Found <?php echo $query->found_posts; ?> Results<br />
                <div class='search-filter-results-list'>
                <?php
                    while ($query->have_posts())
                    {
                        $query->the_post();
                        
                        ?>
                                <div class="posts-double">
                            <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
                            <a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark">
                                <?php 
                                                    $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
                                                    echo '<div class="image" style="background:url('.esc_url($featured_img_url).')"></div>' ?>
                                <?php endif; ?>
                            </a>
                            <div class="content">
                                <a class="title" href="<?php the_permalink() ?>" rel="bookmark">
                                    <?php the_title(); ?>
                                </a>
                                <p class="descriptions">
                                    <?php echo wp_trim_words( get_the_content(), 15, '...' );?>
                                </p>
                                <div class="related-post-category">
                                    <?php the_tags(); 
                                            $post_type = get_post_type(get_the_ID());
                                            $post_name = get_post_type_object(get_post_type())->labels;
                                            if ( $post_type != 'post' ) {
                                                echo '<a href="'.get_post_type_archive_link( $post_type ).'"><span class="'.$post_type.'">'.$post_name->name.'</span></a>';
                                            };
                                            ?>
                                </div>
                            </div>
                            <div class="posts-footer">
                                    <div class="related-time">
                                        <?php echo do_shortcode('[rt_reading_time]'); ?>
                                    </div>
                                    <div class="related-bookmark">
                                        <?php echo do_shortcode('[cbxwpbookmarkbtn]'); ?>
                                    </div>
                                </div>
                        </div>
                
                                <?php
                                
                
                    }
                ?>
                </div>
            <?php
            }
            else
            {
                ?>
                <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
                    <span>End of Results</span>
                </div>
                <?php
            }
        }
            ?>
    #180132

    Trevor
    Participant

    What Display Results Method are you using? If it is your own template, then you would need to know the name of the query variable. The default os for it to be named $wp_query, so some sample code would look like this:

    <p>Found <?php echo $wp_query->found_posts; ?> Results</p>

    #179725

    Anonymous
    Inactive

    OK – used a static title. Re the number of results I’ve copied the code from results.php but it doesn’t return the number:

    <?php if ( have_posts() ) : ?>
    <header class=”page-header”>
    <h1 class=”page-title”>My Title</h1>’
    </header><!– .page-header –>

    Found <?php echo $query->found_posts; ?> Results<br />
    Page <?php echo $query->query[‘paged’]; ?> of <?php echo $query->max_num_pages; ?>

    And for the search term I meant “is possible to show the numbers next to the filters (on the search form)?” rather than on the results page.

    #178171

    Trevor
    Participant

    Hi, this is the new custom results.php file. I cannot access this on your site (it seems to be locked), but this is the content I think you need (I therefore cannot test it):

    <?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>
    	<div class="ptb_loops_wrapper clearfix ptb_grid3">
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    		<article id="post-<?php the_ID();?>" class="ptb_post clearfix post-32080 padi_courses type-padi_courses status-publish has-post-thumbnail hentry ">
                <div class="ptb_items_wrapper entry-content" itemscope="" itemtype="https://schema.org/Article">
                    <div class="ptb_col ptb_col1-1 ptb_col_first">
                        <div class="ptb_module ptb_title">
                            <h2 class="ptb_post_title ptb_entry_title" itemprop="name">
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </h2>
                        </div>
                        <div class="ptb_module ptb_thumbnail">
                            <figure class="ptb_post_image clearfix">
                                <a href="<?php the_permalink(); ?>">
                                    <?php
    				                    if ( has_post_thumbnail() ) the_post_thumbnail("small");
                                    ?>
                                </a>
                            </figure>
                        </div>
                    </div>
                </div>
    		</article>
    		
    		<?php
    	}
    	?>
        </div>
    	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";
    }
    ?>
    #170023

    Trevor
    Participant

    I assume you mean that you are using the Shortcode Display Results method. Did you follow the Customising the Results documentation (so you have your own copy of the results.php file)?

    If you did not, please do so. Edit the child theme copy of the results.php file to remove these lines (29-44):

    	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>
    
Viewing 10 results - 71 through 80 (of 174 total)