alleyinteractive / alleyinteractive/wp-curate

Adjustments to query block context can generate query for arbitrary posts

Open
#457 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
11
Forks
3
PR merge metrics
No merged PRs in 30d

Description

### Description of the bug

When a `wp-curate/query` block contains both hardcoded `wp-curate/post` blocks and a `core/post-template` block, it's possible for the query block's `include` attribute to be reset to an empty array, causing the `post-template` block to query for and display a list of arbitrary posts.

### Steps To Reproduce

Simplified example:

```html





```

In this example pattern, the block markup inside of the query block is static, representing the layout of the section of the page. The query block itself is dynamically generated, first by determining the posts that will appear, then by generating the corresponding `numberOfPosts` and `posts` attributes. Therefore, as in this example, it's possible for there to be more `post` blocks than there are available posts in the pattern.

When this query block renders, all of the inner blocks will render, including the `post-template` block, which will generate a query even though it's known that there will be no posts available to display by virtue of there being more `post` blocks than there are `numberOfPosts`. The resulting query will be equivalent to, in this case, a query with `{"numberOfPosts":2,"postTypes":["post"],"posts":[null, null]}`

### Additional Information

The problem occurs here: https://github.com/alleyinteractive/wp-curate/blob/87bc80eafaf4d16b92c15573c01ed8c54bd01bb4/src/features/class-block-index.php#L174

In scenarios where `$new_include` is empty but it isn't possible for there to be more posts to display, the `wp_curate_stop_queries` query variable should be used rather than setting `include` to `[]`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.