Reverse wordpress SQL CASE Expression
-
Hi everyone, I was working on the search result and got some answers from the support, so I add the code inside the function.php which is working fine, but the search result is kind of odd.
Here’s the code:
add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 2 ); function order_search_by_posttype( $orderby, $wp_query ){ if( ! $wp_query->is_admin && $wp_query->is_search ) : global $wpdb; $orderby = " CASE WHEN {$wpdb->prefix}posts.post_type = 'page' THEN '1' WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' ELSE {$wpdb->prefix}posts.post_type END ASC, {$wpdb->prefix}posts.post_title ASC"; endif; return $orderby; }1. How do I hide homepage on the search result?
2. My first search result list only had a title no excerpt. why?
3. Can this reverse? Will this really affect WordPress DB? if I take the code out will it back to original?Thank you so much for the help.
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
The topic ‘Reverse wordpress SQL CASE Expression’ is closed to new replies.