In my content-search.php template file I did something like this:
<tr id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<td><?php the_post_thumbnail( 'thumbnail' ); ?></td>
<td style="padding: 15px;">
<?php
echo '<h6>' . ucfirst( get_post_type( get_the_ID() ) ) . '</h6>';
the_title( sprintf( '<h5><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h5>' );
echo '<p>' . get_the_excerpt() . '</p>';
?>
</td>
</tr>
It returns posts image, post type name in English, title and excerpt on search results page. Posts, pages or another custom post types by searched term. I need to display post type name translated into another language.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Based on a previous Q&A, How to get current get_post_types name?, you could use get_post_type_object() to get the whole post type object, which will have the translated name in it.
$post_type_object = get_post_type_object(get_post_type());
if ( $post_type_object ) {
echo esc_html( $post_type_object->labels->singular_name );
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
