Skip Navigation

[Resolved] How do I sort the product search output by Post body

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 6 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1122070

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

#1122565

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - When you add search using views, it will allow you to either search by post title or post title and body.

Please check following Doc:
=> https://toolset.com/documentation/user-guides/filtering-views-for-a-specific-text-string-search/#add-a-search-query-filter-to-your-view

#1122904

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.

#1123606

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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 );

Where:
- Replace 9999 with your original view Id.