Sử dụng pre_get_posts để chỉnh sửa search (ok)
https://www.hoangweb.com/wordpress/wordpress-posts-filter-hook-pre_get_posts
Chú ý: search mặc định là :
'post', 'page'


<?php
function searchfilter($query) {
if ($query->is_search && !is_admin()) {
$query->set('post_type', array('post', 'page'));
$query->set( 'cat', '19' );
$query->set( 'posts_per_page', 2 );
}
return $query;
}
add_filter('pre_get_posts', 'searchfilter');
?>
Previous[PRE_GET_POSTS] Lọc danh sách bài viết trong wordpress sử dụng action hook – pre_get_posts (ok)NextCách lấy dữ liệu bài viết trong wordpress full HOÀNG QUÁCH (ok)
Last updated
Was this helpful?