alleyinteractive / alleyinteractive/wp-curate

Adjustments to query block context can generate query for arbitrary posts

未关闭
#457 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
PHP
星标
11
派生
3
PR 合并指标
30 天内没有已合并 PR

描述

### 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 `[]`.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。