사용자 정의 게시 유형 (post_type
)이 있고 게시 유형이 product
인 항목이 검색 결과에 앞서 나타남을 보장하려면 어떻게해야합니까? 가급적 간단히 쿼리의 일부분을 변경하여 order by
부분을 변경하십시오. 검색어로 MYSQL 주문
ORDER BY posts.post_type DESC, posts.post_date DESC
이 testimonial
의 또 다른 포스트 유형을 제외하고, 작동은 DESC
에 product
전에 온다. ASC
에서 다른 맞춤 게시물 유형 articles
은 product
앞에 있지만 처음에는 post_date
순으로 주문해야합니다. post_date
으로 주문하십시오.
전체 코드 :
add_filter('posts_orderby','search_sort_custom',10,2);
function search_sort_custom($orderby, $query)
{
global $wpdb;
if(!is_admin() && is_search()) {
$orderby = $wpdb->prefix."posts.post_type DESC, {$wpdb->prefix}posts.post_date DESC";
}
return $orderby;
}
감사를 할 수있는 나는 할 수있다! post_type = '제품'DESC, posts.post_type = '제품'DESC, posts.post_date의 DESC – Martin
사과를하면 아직 그룹화를 유지하는 오래된 표현 .. 업데이 트를 참조하십시오. 비교 결과는 1 또는 0 (true/false)을 반환하므로 제안 내용이 원본과 동일합니다. – Arth
감사합니다 Arth ... 그래서 이것은 post_date DESC에 의해 정렬 된 모든 제품을 반환 할 것입니다. 그렇다면, 내가 겪어 온 그대로이기 때문에, 굉장합니다. – Martin