Im using custom WP_Query on a single post page (it shows a list of recent posts):
$recent = new WP_Query($args);
while ($recent->have_posts()) {
$recent->the_post();
get_template_part('template-parts/content', get_post_format());
}
The problem is: in template I check is_single() condition, which always returns true (with no arguments passed). When I try is_single($post), sometimes it returns true, sometimes false.
UPD 1:
I use template-parts/content.php template in my theme folder. The code is something like that:
if ( is_single($post) ) :
the_title( '<h1 class="entry-title pb-1 '.ta_content_paragraphs_paddings().'">', '</h1>' );
else :
the_title( '<h2 class="entry-title pb-1 '.ta_content_paragraphs_paddings().'"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
endif; ?>
UPD 2: I found why it returns true sometimes with $post given as argument, it happens when my single post title is the same as the recent post title. This part of code in class-wp-query, function is_single:
} elseif ( in_array( $post_obj->post_title, $post ) ) { // returns here
return true;
Is it normal to check post title for telling me its a single page?