Đăng ngày 2 Tháng mười hai, 2008 trong mục WP Tips-Tricks | 3,538 lượt xem

If you intend to exclude pages from search results, you can use the Simply-Exclude plugin. However, another solution that works pretty well is to add a filter in functions.php to only include posts categories instead of excluding pages from search results:

1
2
3
4
5
6
7
function mySearchPostsFilter($query) {
if ($query->is_search()) {
$query->set('cat','12,14,16,17,18'); // your category IDs
}
return $query;
}
add_filter('pre_get_posts','mySearchPostsFilter');

Just replace the posts category IDs (’12,14,16,17,18′) by your owns and it should work. That’s all!

Đăng ký nhận bài viết qua email
digg delicious stumbleupon technorati Google live facebook Sphinn Mixx newsvine reddit yahoomyweb

0 phản hồi cho “WP Tip – Exclude pages from search results”

  1. Bài này vẫn chưa có comment. Sao bạn không là người đầu tiên nhỉ?

Viết comment

Chức năng lọc comment của blog đang được kích hoạt vì thế những comment có từ ngữ thô tục hoặc có chứa một số link sẽ bị coi là spam. Vui lòng đừng bấm nút “Gửi Comment” hai lần, comment của bạn sẽ hiển thị sau khi đã qua kiểm duyệt.
Off Auto TELEX VNI VIQR VIQR*