Site logo

Archived topic

Limit Search Result Description to 55 words or less

13 replies · Started by Melissa on June 25, 2021

Viewing posts 1–14 of 14

Currently when someone uses the search function it returns hundreds of Full length posts. I would like to limit the content length of the search result description to 55 words, much like an excerpt, rather than the full post content of each match.

Can someone help me out with that?

Hi Melissa,

That's strange. The search result page should have the same excerpt if it's set in the customizer.

You can test it here by searching a keyword like "fastest":
https://gpsites.co/marketer/

Are you using excerpt in the posts page?

I guess I'm not sure what you mean, currently, when you go to my homepage and enter a search word, say, "Keto" it will return full length posts, not excerpts.

if you're referring to wp-admin> settings> reading> for each post> Summary (is the checked option)

Is there some other setting I'm overlooking?

That setting is currently set to 15, but as I mentioned, excerpts appear to be ignored for my search.

Also, I just noticed when I did a search that it's not showing posts/pages in the results, it's being overwritten by bbpress search topics instead.

Any chance you can disable all plugins except GP Premium to eliminate conflicts from other plugins first

Let me know :)

That didn't make a difference (aside from completely disabling my forums). For some reason the site search is overwritten by the bbpress search.

For some reason the site search is overwritten by the bbpress search.

I'd assume that's the reason.

Are you sure disabling bbPress plugin didn't solve the issue?

Can you create a staging site and disable all plugins there so we can take a closer look?

It might be good to check with bbPress' support team to see if they can help as well.

Thank you for your help, I discovered the error - bbpress caused a duplicate content-search page.

Now that I've removed that, is there a way to include topics & replies in the search results? Normally, I'd use something like,

$query_options = array(
    'post_type' => array('post', 'forum', 'topic', 'reply', 'page'),
    /* More stuff here*/

)

;

but I can't locate the post type array for the search.

Thank you for that page, but I'm not clear on how to add topics and replies to those filters.

okay.. I tried :

add_filter( 'generate_navigation_search_output', function() {
    printf(  
        '<form method="get" class="search-form navigation-search" action="%1$s">
            <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
            <input type="hidden" name="post_type" value="post,topic" />
        </form>', 
        esc_url( home_url( '/' ) ), 
        esc_attr( get_search_query() ),   
        esc_attr_x( 'Search', 'label', 'generatepress' ) 
    ); 
} );

but it didn't return results for posts and topics. It only returned Posts.

then I tried:

add_filter( 'generate_navigation_search_output', function() {
    printf(  
        '<form method="get" class="search-form navigation-search" action="%1$s">
            <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
            <input type="hidden" name="post_type" value="post" />
	    <input type="hidden" name="post_type" value="topic" />
        </form>', 
        esc_url( home_url( '/' ) ), 
        esc_attr( get_search_query() ),   
        esc_attr_x( 'Search', 'label', 'generatepress' ) 
    ); 
} );

but it only returned topics, not posts....

then I tried:

add_filter( 'generate_navigation_search_output', function() {
    printf(  
        '<form method="get" class="search-form navigation-search" action="%1$s">
            <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
            <input type="hidden" name="post" value="post" />
			<input type="hidden" name="topic" value="topic" />
        </form>', 
        esc_url( home_url( '/' ) ), 
        esc_attr( get_search_query() ),   
        esc_attr_x( 'Search', 'label', 'generatepress' ) 
    ); 
} );

in case I was supposed to be renaming the "name" field and that returned zero results across the board.

SOLVED:

add_filter( 'generate_navigation_search_output', function() {
    printf(  
        '<form method="get" class="search-form navigation-search" action="%1$s">
            <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
            <input type="hidden" name="post_type[]" value="post" />
            <input type="hidden" name="post_type[]" value="topic" />
            <input type="hidden" name="post_type[]" value="reply" />
        </form>', 
        esc_url( home_url( '/' ) ), 
        esc_attr( get_search_query() ),   
        esc_attr_x( 'Search', 'label', 'generatepress' ) 
    ); 
} );

Good job!

Thanks for sharing your code as well :)

This archived topic is closed to new replies.