-
Search Results
-
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 } } ?>Hello!
I’m using search and filter pro v2.4.3 with Relevanssi.
This code displays the results on each custom search.
<?php global $searchandfilter; $analisar_home = $searchandfilter->get(312)->current_query(); if ((!$analisar_home->is_filtered())&&($analisar_home->get_search_term()=="")) { $args = array( 'post_type' => array( 'post', 'ebooks', 'podcasts', 'videos' ), 'cat' => 5, 'posts_per_page' => 5, 'post_status' => 'publish', 'orderby' => 'date', 'posts_per_page' => -1, ); $posts = new WP_Query( $args ); if( $posts->have_posts() ) : ?> <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( $posts->have_posts() ) : $posts->the_post(); ?> <div class="search-box"> <?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(), 25, '...' );?> </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>'; }; $terms = get_the_category( $post->ID ); //Get all the terms foreach ($terms as $term) { //Cycle through terms, one at a time // Check and see if the term is a top-level parent. If so, display it. $parent = $term->parent; if ( $parent=='0' ) { $term_id = $term->term_id; //Define the term ID $term_link = get_term_link( $term); //Get the link to the archive page for that term $term_name = $term->name; $term_slug = $term->slug; echo '<a class="' . $term_slug . '" href="' . $term_link . '"><span class="label">' . $term_name . '</span></a>'; } } ?> </div> <div class="related-post-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> </div> <?php endwhile; wp_reset_postdata(); else : esc_html_e( 'Não conseguimos encontrar nenhum resultado...', 'text-domain' ); endif; } else //Inicio fim { ?> <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 class="search-box"> <?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(), 25, '...' );?> </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>'; }; $terms = get_the_category( $post->ID ); //Get all the terms foreach ($terms as $term) { //Cycle through terms, one at a time // Check and see if the term is a top-level parent. If so, display it. $parent = $term->parent; if ( $parent=='0' ) { $term_id = $term->term_id; //Define the term ID $term_link = get_term_link( $term); //Get the link to the archive page for that term $term_name = $term->name; $term_slug = $term->slug; echo '<a class="' . $term_slug . '" href="' . $term_link . '"><span class="label">' . $term_name . '</span></a>'; } } ?> </div> <div class="related-post-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> </div> <?php } ?> <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 } ?>This code lists posts without any search. The problem is, when I use any filter on the search, the results dont show custom posts types, only regular posts.
Here you can see that my configs are right.

Please, can you help me? I’m trying to figure out at least 4 days what is going on…
Thanks