Forums › Forums › Search & Filter Pro › Custom Posts type listing and searching
- This topic has 2 replies, 2 voices, and was last updated 6 years, 11 months ago by
Anonymous.
-
Anonymous(Private) June 4, 2018 at 7:07 pm #179684
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
Trevor(Private) June 5, 2018 at 8:35 am #179696Hi
You have The following Post Types selected:
Posts
Guis Educativos
Ebooks
Videos
PodcastsCan you test the search with only one of these at a time (so do 5 tests).
The search will only work properly if the post type has been translated, as you are using a translation plugin. For example, if Videos have not been translated, then the behavior you describe will happen.
-
AuthorPosts