由于某种原因,站点搜索正确显示结果,结果的链接已断开。
例
<a href="http://example.com/health-safety/">Health Safety</a>
这是我从搜索结果中得到的。事实上,该链接应该已转到以下页面。
http://example.com/careers/working-for-us/
从管理员那里,我已经在带有类别的帖子下输入了此信息。
这是PHP代码(我认为PHP代码没有任何问题)
<?php if ( have_posts() ) : ?>
<ul class="searchul table-striped">
<?php while ( have_posts() ) : the_post(); ?>
<li>
<h4 ><a href="<?php permalink_link();?>"><?php the_title(); ?></a></h4>
<?php the_excerpt();?>
</li>
<?php endwhile; ?>
</ul>
<div class="search-results-paginglinks"><?php posts_nav_link(); ?></div>
<?php else : ?>
<div class="search_result_error" style="margin-top: 25px;"><?php _e('Sorry, Your search did not match any criteria.' ); ?></div>
<?php endif; ?>
更多信息我尝试将此代码添加到函数.php。这样做只是查询和搜索页面,而不是帖子。我需要页面和帖子
/* Search */
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'pages');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
首先它是
the_permalink()
,而不是permalink_link()
其次,帖子类型称为页面而不是页面,用于您的pre_get_posts函数。