
Để thực hiện loại trừ Pages ra khỏi kết quả tìm kiếm trong website WordPress, bạn chỉ cần thực hiện theo các bước hướng dẫn bên dưới là xong.
Bước 1: Đăng nhập trang quản trị > Vào Giao diện > Theme Editor
Bước 2: Mở file functions.php của theme đang dùng
Bước 3: Thêm đoạn code sau vào cuối file
// Loại trừ pages và custom post type trong kết quả tìm kiếm WordPress
function SearchFilter($query) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
Chúc các bạn thực hiện thành công!
Bình luận bài viết (4)
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.bh/register/person?ref=QCGZMHR6