Site logo

Archived topic

remove the meta from search results

3 replies · Started by Josh on November 4, 2020

Viewing posts 1–4 of 4

How can I remove the "date BY author" from the search results page?

Also, is there any way to add my custom post to the search results?

Hi,

Also, is there any way to add my custom post to the search results?

To clarify: Do you mean, you want to use a custom post list plugin to display search results?

How can I remove the “date BY author” from the search results page?

Can you link us to the site in question? We should be able to prevent it from displaying w/ custom CSS.

You can provide the site details on the Private Information text area. Thank you.

I created my own CPT with no plugin.

My custom post type does show up, but i guess I was hoping that it could return results by post type.

example
posts
1
2
2
Pages
1
2
Products
1
2

Site details below.

Oh right that makes sense. By default, WordPress doesn't include custom post types in its search result.

For starters let's try making your search result include your custom post type by adding this PHP snippet:

function include_cpt_search( $query ) {
    if ( $query->is_search ) {
		$query->set( 'post_type', array( 'post', 'page', 'custom_post_type' ) );
    }
    return $query;
}
add_filter( 'pre_get_posts', 'include_cpt_search' );

Simply add your custom post type inside the $query->set post_type array().
Reference: https://www.dhirenpatel.me/include-custom-post-type-wordpress-search-result/#:~:text=In%20the%20WordPress%20default%20search,third%20party%20free%20WordPress%20plugin.

As for separating posts results by post type, perhaps this can help:
https://wordpress.stackexchange.com/posts/181807/revisions

Here's how to add PHP snippets.:
https://docs.generatepress.com/article/adding-php/

This archived topic is closed to new replies.