Site logo

Archived topic

Display only post / page title and selected meta data in search results

3 replies · Started by Denise on December 9, 2017

Viewing posts 1–4 of 4

Hello GP Friends,

How can I modify the search results page so that it displays only the post title or page title (as a link) in the search results, followed by a second line with customized meta data. The meta data looks like this with the date and category separated by a pipe.
2017 Dec | Category

I’m using GP Pro and have a child theme.

Best wishes,
Denise

Hi there,

You could try this CSS:

.search .entry-summary, 
.search .entry-content, 
.search .post-image {
    display: none;
}

Then this PHP:

add_filter( 'generate_post_date_output', 'tu_add_cats_to_date' );
function tu_add_cats_to_date( $output ) {
    $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );

    if ( $categories_list && is_search() ) {
        return $output . ' | ' . $categories_list;
    }

    return $output;
}

Brilliant!
Thanks Tom. That worked perfectly.

You're welcome :)

This archived topic is closed to new replies.