diff --git a/packages/block-library/src/latest-posts/edit.js b/packages/block-library/src/latest-posts/edit.js index 433810e467b0f..e8811a310787a 100644 --- a/packages/block-library/src/latest-posts/edit.js +++ b/packages/block-library/src/latest-posts/edit.js @@ -70,7 +70,7 @@ class LatestPostsEdit extends Component { render() { const { attributes, setAttributes, latestPosts } = this.props; const { categoriesList } = this.state; - const { displayPostContentRadio, displayPostContent, displayPostDate, postLayout, columns, order, orderBy, categories, postCount, excerptLength } = attributes; + const { displayPostContentRadio, displayPostContent, displayPostDate, postLayout, columns, order, orderBy, categories, postsToShow, excerptLength } = attributes; const inspectorControls = ( @@ -113,13 +113,13 @@ class LatestPostsEdit extends Component { setAttributes( { order: value } ) } onOrderByChange={ ( value ) => setAttributes( { orderBy: value } ) } onCategoryChange={ ( value ) => setAttributes( { categories: '' !== value ? value : undefined } ) } - onNumberOfItemsChange={ ( value ) => setAttributes( { postCount: value } ) } + onNumberOfItemsChange={ ( value ) => setAttributes( { postsToShow: value } ) } /> { postLayout === 'grid' && postCount ? - latestPosts.slice( 0, postCount ) : + const displayPosts = latestPosts.length > postsToShow ? + latestPosts.slice( 0, postsToShow ) : latestPosts; const layoutControls = [ @@ -244,13 +244,13 @@ class LatestPostsEdit extends Component { } export default withSelect( ( select, props ) => { - const { postCount, order, orderBy, categories } = props.attributes; + const { postsToShow, order, orderBy, categories } = props.attributes; const { getEntityRecords } = select( 'core' ); const latestPostsQuery = pickBy( { categories, order, orderby: orderBy, - per_page: postCount, + per_page: postsToShow, }, ( value ) => ! isUndefined( value ) ); return { latestPosts: getEntityRecords( 'postType', 'post', latestPostsQuery ), diff --git a/packages/block-library/src/latest-posts/index.php b/packages/block-library/src/latest-posts/index.php index d3a7a30c90c2f..e8cd3c6fb6612 100644 --- a/packages/block-library/src/latest-posts/index.php +++ b/packages/block-library/src/latest-posts/index.php @@ -14,7 +14,7 @@ */ function render_block_core_latest_posts( $attributes ) { $args = array( - 'posts_per_page' => $attributes['postCount'], + 'posts_per_page' => $attributes['postsToShow'], 'post_status' => 'publish', 'order' => $attributes['order'], 'orderby' => $attributes['orderBy'], @@ -135,7 +135,7 @@ function register_block_core_latest_posts() { 'categories' => array( 'type' => 'string', ), - 'postCount' => array( + 'postsToShow' => array( 'type' => 'number', 'default' => 5, ),