Tell us what you are trying to do?
I like to sort the search output by Post body. How do I do this?
Is there any documentation that you are following?
No
Is there a similar example that we can see?
No
What is the link to your site?
bcecltd.com/download3
You are addressing the text search of Post Title or Post Title and Post Body.
What I am asking about is "how to sort the search output by Post Body". That is, when the matching products are found, how do I sort them not by the Post Title but by Post Body.
Also I asked previously how to search only the Post Body. I do not want to search the Post Title and Post Body. Just the Post Body. I do not see that option.
What I am asking about is "how to sort the search output by Post Body". That is, when the matching products are found, how do I sort them not by the Post Title but by Post Body.
==> Well - as you already seen with our GUI there is no such feature available that you can implement to sort by post body. Please check following Doc where you will find all available options for sorting:
- https://toolset.com/documentation/user-guides/allowing-visitors-to-sort-the-front-end-results/
Also I asked previously how to search only the Post Body. I do not want to search the Post Title and Post Body. Just the Post Body. I do not see that option.
=> Again, there is no such option but I think you can work around this by adding following code to your current theme's functions.php file.
function func_search_in_post_content( $search, $wp_query ){
global $wpdb;
global $WP_Views;
if($WP_Views->current_view == 9999){
if ( empty( $search ) )
return $search; // skip processing - no search term in query
$q = $wp_query->query_vars;
$search = '';
foreach ( (array) $q['search_terms'] as $term ) {
$term = esc_sql( like_escape( $term ) );
$search = " AND ($wpdb->posts.post_content REGEXP '[[:<:]]{$term}[[:>:]]')";
}
}
return $search;
}
add_filter( 'posts_search', 'func_search_in_post_content', 1000, 2 );