我希望 WP 搜索引擎仅搜索帖子(现在它搜索帖子和页面) - 有人知道该怎么做吗?
最佳答案
首先,在主题的functions.php 文件中添加以下函数:
function is_type_page() { // Check if the current post is a page
global $post;
if ($post->post_type == 'page') {
return true;
} else {
return false;
}
}
接下来,在主题的 search.php 文件中(显示搜索结果的位置),您需要在循环后面添加以下行。它应该如下所示:
<?php while (have_posts()) : the_post(); ?>
<?php if (is_type_page()) continue; ?>
关于wordpress - 仅搜索 WordPress 中的帖子(而非页面),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14039908/