Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Template. Return No results found in PHP to match JS. #36225

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/block-library/src/post-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ function render_block_core_post_template( $attributes, $content, $block ) {

$query = new WP_Query( $query_args );

if ( ! $query->have_posts() ) {
return '';
}

$classnames = '';
if ( isset( $block->context['displayLayout'] ) && isset( $block->context['query'] ) ) {
if ( isset( $block->context['displayLayout']['type'] ) && 'flex' === $block->context['displayLayout']['type'] ) {
Expand All @@ -49,6 +45,10 @@ function render_block_core_post_template( $attributes, $content, $block ) {

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) );

if ( ! $query->have_posts() ) {
return "<p $wrapper_attributes>" . __( 'No results found.' ) . '</p>';
}

$content = '';
while ( $query->have_posts() ) {
$query->the_post();
Expand Down