Skip to content

Commit

Permalink
Merge pull request #2825 from 10up/feature/related-posts-postid-context
Browse files Browse the repository at this point in the history
Support an accurate preview of the Related Posts block inside query loop block
  • Loading branch information
felipeelia committed Jun 21, 2022
2 parents b05b3d0 + 2f3830a commit 5258aba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/js/blocks/related-posts/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Edit extends Component {
};

// Use 0 if in the Widgets Screen
const postId = wp.data.select('core/editor').getCurrentPostId() ?? 0;
const { context: { postId = 0 } = {} } = this.props;

wp.apiFetch({
path: addQueryArgs(`/wp/v2/posts/${postId}/related`, urlArgs),
Expand Down
1 change: 1 addition & 0 deletions assets/js/blocks/related-posts/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ registerBlockType('elasticpress/related-posts', {
default: 5,
},
},
usesContext: ['postId'],

/**
* Handle edit
Expand Down

0 comments on commit 5258aba

Please sign in to comment.