-
AuthorSearch Results
-
February 23, 2017 at 9:04 am #92230
In reply to: Check if a select list data is selected
AnonymousInactiveHi 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ément(s) trouvés(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.
February 21, 2017 at 8:29 am #91601In reply to: Display author name in template
AnonymousInactiveHello 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ément(s) trouvés(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.
February 21, 2017 at 8:14 am #91599
AnonymousInactiveYes 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.
PierreFebruary 20, 2017 at 4:51 pm #91473
AnonymousInactiveOoops. 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"; } } ?>
February 2, 2017 at 5:25 pm #87657In reply to: Force selection?
TrevorParticipantHi 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 lineecho '<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"; } } ?>
January 26, 2017 at 2:55 pm #85731
TrevorParticipantJust in case this happens again, this is the code I wrote:
<?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(5048)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo ''; } 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> <div class="slz-shortcode sc_block_posts "><div class="slz-template-03 "> <div class="slz-list-block slz-column-2"> <?php while ($query->have_posts()) { $query->the_post(); ?> <div class="item"> <div class="slz-block-item-01 style-1"> <?php if ( has_post_thumbnail() ) {?> <div class="block-image"> <a href="<?php the_permalink(); ?>" class="link"> <?php the_post_thumbnail("full", array( 'class' => 'img-responsive' ));?> </a> </div> <?php } ?> <div class="block-content"> <div class="block-content-wrapper"> <a class="block-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <ul class="block-info"> <li><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><span class="author-label">By </span><span class="author-text"><?php the_author(); ?></span></a></li> <li><a href="<?php the_permalink(); ?>" class="link date"><?php the_date(); ?></a></li> <li><a href="<?php the_permalink(); ?>#comments" class="link comment"><?php comments_number();?></a></li> <li><a href="<?php the_permalink(); ?>" class="link view">?? Views</a> </li> <li><?php the_category(); ?></li> </ul> <div class="block-text"><?php echo get_the_excerpt(); ?></div> </div> </div> </div> </div> <?php } ?> </div> </div></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"; } } ?>
January 19, 2017 at 12:01 pm #83677In reply to: How display Result page as Grid ?
TrevorParticipantI have written a new results.php for you:
<?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="col-9 hb-equal-col-height hb-main-content"> <div id="hb-blog-posts" class="hb-blog-grid masonry-holder clearfix" data-layout-mode="fitRows" data-categories="" data-column-size="col-4"> <?php while ($query->have_posts()) { $query->the_post(); ?> <article id="post-<?php echo get_the_ID();?>" class="col-4 post-<?php echo get_the_ID();?> post type-post status-publish format-standard has-post-thumbnail hentry" itemscope="" itemtype="http://schema.org/BlogPosting"> <div class="featured-image"> <a href="<?php the_permalink(); ?>"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail("small"); ?> <div class="featured-overlay"></div> <div class="item-overlay-text" style="opacity: 0;"> <div class="item-overlay-text-wrap" style="padding-top: 0px;"> <span class="plus-sign"></span> </div> </div> <?php } ?> </a> </div> <div class="post-content"> <div class="post-header"> <h2 class="title" itemprop="headline"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> </div> <p><?php echo get_the_excerpt(); ?> <br /><a href="<?php the_permalink(); ?>" class="read-more">Read More</a> </p> </div> </article> <?php } ?> </div> </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"; } ?>
January 6, 2017 at 5:33 pm #80566In reply to: displaying a search counter
TrevorParticipantPart of it uses this, I think:
<?php echo $query->found_posts; ?>
December 29, 2016 at 7:49 pm #79193
TrevorParticipantOK, 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 (change the number255
for the ID number of your search form and change the lineecho '<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):<?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(255)->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"; } } ?>
December 27, 2016 at 9:53 am #78756In reply to: Finding maximum number of posts
TrevorParticipantIt MIGHT be possible using PHP, something like this:
<?php global $wp_query; ?> <div>Found <?php echo $wp_query->found_posts; ?> Posts</div>
But the query name might be the issue, because it depends on your theme. I stumbled on this by accident because I was trying to find how many posts there were after filtering, but this code gave me the total number before filtering.
For my own needs I have spent over a week on this without any joy, so I am fairly sure I can’t offer much more help.
-
AuthorSearch Results