admin管理员组文章数量:1122826
EDIT: So I've done some troubleshooting and it seems my theme isn't showing woocommerce search results. The 2017 theme does so I am trying to figure out what my theme is missing. I suspect something in the functions.php
file. It's something I'm leaving out, not something I've included that's interfering, because I deleted all my code out of the functions file line by line and nothing changed.
I have some custom code I have used elsewhere without any trouble. I tried just copying it over to my new theme and for some reason, its not working. The search results show 1-10 of 54 but the first page only shows four results. The rest of the pages show nothing. I can't figure what I could be doing wrong.
In functions.php
:
function wpse_106121_posts_count( $wp_query = null ) {
if ( ! $wp_query )
global $wp_query;
$posts = min( ( int ) $wp_query->get( 'posts_per_page' ), $wp_query->found_posts );
$paged = max( ( int ) $wp_query->get( 'paged' ), 1 );
$count = ( $paged - 1 ) * $posts;
printf(
'%d - %d of %d',
$count + 1,
$count + $wp_query->post_count,
$wp_query->found_posts
);
}
In search.php
:
<?php if ( have_posts() ) : ?>
<p><?php wpse_106121_posts_count() ?></p>
<?php while ( have_posts() ) : the_post();
if ( '' !== get_post()->post_content ) : ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>">Read More</a></p>
<hr class="divider">
<?php endif; endwhile; else : ?>
<p>No posts found.</p>
<?php endif; ?>
<div class="navigation"><?php
global $wp_query;
$big = 99999;
$translated = __( '', 'themename' );
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'next_text' => __('NEXT >'),
'prev_text' => __('< PREV'),
) );
?></div>
EDIT: So I've done some troubleshooting and it seems my theme isn't showing woocommerce search results. The 2017 theme does so I am trying to figure out what my theme is missing. I suspect something in the functions.php
file. It's something I'm leaving out, not something I've included that's interfering, because I deleted all my code out of the functions file line by line and nothing changed.
I have some custom code I have used elsewhere without any trouble. I tried just copying it over to my new theme and for some reason, its not working. The search results show 1-10 of 54 but the first page only shows four results. The rest of the pages show nothing. I can't figure what I could be doing wrong.
In functions.php
:
function wpse_106121_posts_count( $wp_query = null ) {
if ( ! $wp_query )
global $wp_query;
$posts = min( ( int ) $wp_query->get( 'posts_per_page' ), $wp_query->found_posts );
$paged = max( ( int ) $wp_query->get( 'paged' ), 1 );
$count = ( $paged - 1 ) * $posts;
printf(
'%d - %d of %d',
$count + 1,
$count + $wp_query->post_count,
$wp_query->found_posts
);
}
In search.php
:
<?php if ( have_posts() ) : ?>
<p><?php wpse_106121_posts_count() ?></p>
<?php while ( have_posts() ) : the_post();
if ( '' !== get_post()->post_content ) : ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>">Read More</a></p>
<hr class="divider">
<?php endif; endwhile; else : ?>
<p>No posts found.</p>
<?php endif; ?>
<div class="navigation"><?php
global $wp_query;
$big = 99999;
$translated = __( '', 'themename' );
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'next_text' => __('NEXT >'),
'prev_text' => __('< PREV'),
) );
?></div>
Share
Improve this question
edited Feb 17, 2017 at 4:07
Heather
asked Feb 17, 2017 at 0:11
HeatherHeather
4892 gold badges8 silver badges21 bronze badges
1 Answer
Reset to default 0Turns out I had an extra if statement in my search.php
file that was filtering out content that didn't contain a proper excerpt.
本文标签: phpSearch not showing all results
版权声明:本文标题:php - Search not showing all results 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281346a1926289.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论