I want to remove the post meta from all post types that are not "posts" from my site or at least from the search results.

Im currently using the Jnews theme and in the search results page I get all post types (posts, pages, products) but I'm only interested in leaving the post meta (.jeg_post_meta) for posts and removing it for all other post types like pages, products and others that the results page can bring.

.jeg_post_meta is the style class that the search results page is using for all meta from all post types.

1 Answer 1


You didn't provide any of the output code for the search results output, so what I've provided below is a guess based on how things 'should' work - chances are things will look different in your theme so you'll need to sort out how to apply the same logic.

In your search results template (content-search.php maybe?) you'll have your search results pulled in and they'll all be in a variable like so:


That'll be the results of the search query (may be named something different)...

So in your while() loop you'll want to check get the 'type' for each result:

$type = $search_query->post->post_type;

Then before you output the HTML and data for the post meta, you'll check to see if the type matches post, like so:

if( $type == 'post' ) :
  //your post meta output code

Putting the whole thing together... and remember, lots of guesswork in here:

    while( $search_query->have_posts() ) {
        $type = $search_query->post->post_type;
        if( $type == 'post' ) :
            echo '<div class="jeg_post_meta">';
                echo 'By ' . the_author_posts_link() . 'on ' . the_time( 'F jS, Y' ) . 'in ' . the_category( ', ' ) . '.';
            echo '</div>';
        echo '<div class="jeg_post_content">';
        echo '</div>';

Just a reminder though that you shouldn't be editing a third-party theme because your edits will get lost if/when it updates and you'll have to start over. So you want to do this in a child theme where you're overriding existing templates and content parts.

  • Thanks, and sorry for not providing the output code, first time using this site for asking a question. I tried to search for something close to the content-search.php but only found 3 files that could match the description. search.php searcharchive.php search-result.php Commented Feb 22, 2021 at 20:57
  • It'd be search-result.php and you may also need to do searcharchive.php, but you should be able to skip over search.php as that is most likely just the actual search itself or a 'search page'. (Oh, and no need to apologize, we're all here to help one another, I was just pointing it out so that you didn't expect to find the exact same thing.) Commented Feb 22, 2021 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.