Show name of post type in WordPress search results

502 Views Asked by At

I'm currently customizing my search.php template for my WordPress website. Been trying to show the title of the post type of every search result that appears. So far have used 'get_post_type()' and 'post_type_archive_title' (below), but none seem to pulling anything through. I have tried to move the code around different places too.

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <a class="link" href="<?php the_permalink();?>">
        <div class="row">
        <div class="col-md-12">
            <header class="entry-header">
                <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
                <div class="post-type"><?php post_type_archive_title(); ?></div>
            </header><!-- .entry-header -->
            <div class="entry-summary">
                <?= preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', get_the_excerpt() ); ?>
            </div><!-- .entry-summary -->   
        </div>
        </div>
    </a>
</article><!-- #post-## -->
'''
0

There are 0 best solutions below