Skip to content

Commit

Permalink
Fixup a bug with server rendering count
Browse files Browse the repository at this point in the history
  • Loading branch information
George Hotelling committed Apr 14, 2020
1 parent 3823255 commit 699885e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function register_block_core_query() {
* @return array Return an array of args.
*/
function core_query_attributes_to_critera( $criteria ) {
if ( $criteria[ 'specificMode' ] == 1 ) {
if ( isset( $criteria[ 'specificMode' ] ) && $criteria[ 'specificMode' ] == 1 ) {
$args = array(
'post_status' => 'publish',
'p' => $criteria[ 'singleId' ],
Expand Down Expand Up @@ -70,22 +70,25 @@ function core_query_attributes_to_critera( $criteria ) {
function render_block_core_query( $attributes ) {
$blocks = ! empty( $attributes['blocks'] ) ? $attributes['blocks'] : array();
$args = core_query_attributes_to_critera( $attributes['criteria'] );
$posts_to_show = $args['posts_per_page'];
$args['posts_per_page'] = $args['posts_per_page'] + count( Blocks_Query::$displayedPostIds );

$query = new WP_Query( $args );
$posts_shown = 0;

ob_start();
?>
<div class="<?php echo esc_attr( $attributes['className']); ?>">
<?php if ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() ) : ?>
<?php while ( $query->have_posts() && $posts_shown < $posts_to_show) : ?>
<?php
$query->the_post();
$id = get_the_ID();
if ( in_array( $id, Blocks_Query::$displayedPostIds ) ) {
continue;
} else {
array_push( Blocks_Query::$displayedPostIds, $id );
$posts_shown++;
}
?>
<div class="entry-wrapper">
Expand All @@ -109,8 +112,8 @@ function render_block_core_query( $attributes ) {
}
?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php
return ob_get_clean();
Expand Down

0 comments on commit 699885e

Please sign in to comment.