Cyber Week Sale! Get $20 off GP Premium, $40 off our new Lifetime license, and 45% off license renewals/extensions! Learn more

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

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #445905
    Denise

    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

    GP Premium 1.5.6
    #446020
    Tom
    Lead Developer
    Lead Developer

    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;
    }
    #446247
    Denise

    Brilliant!
    Thanks Tom. That worked perfectly.

    #446338
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.