WPIntell

Source evidence

You should replace your query

Single Post Query Loop Selector · support · 2024-03-19T11:36:00+00:00

questionsentiment
mediumseverity
0.84relevance
5replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

4 / 27 rows with source links

14.8% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

23 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
Willy Bahuaud resolved
Actually, when you apply the filter query_loop_block_query_vars on pre_render_block, all the query after your block will be affected. You should instead use the hook outside pre_render_block, and fetch your conditions inside this hook : add_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\filter_my_query', 10, 2 ); function filter_my_query( $query, $block ) { if ( isset( $block->parsed_block['attrs']['namespace'] ) && 'creativeandrew/single-post-query-loop-selector' === $block->parsed_block['attrs']['namespace'] ) { if ( isset( $block->parsed_block['attrs']['query']['include'] ) ) { $query['post__in'] = $block->parsed_block['attrs']['query']['include']; } } return $query; } Have a nice day ! This topic was modified 2 years, 2 months ago by Willy Bahuaud . This topic was modified 2 years, 2 months ago by Willy Bahuaud . Sorry, wrong code… updated here: add_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\filter_my_query', 10, 2 ); function filter_my_query( $query, $block ) { if ( ! empty( $block->context['query']['include'] ) ) { $query['post__in'] = $block->context['query']['include']; } return $query; } Hi Willy , Thanks a lot for your message. Yes, this was reported here as well: https://github.com/creative-andrew/single-post-query-loop-selector/issues/1 I will be amending the code shortly and submitting a new release! However, wouldn’t it be better to do: add_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\filter_my_query', 10, 2 ); function filter_my_query( $query, $block ) { if ( isset( $block->parsed_block['attrs']['namespace'] ) && 'creativeandrew/single-post-query-loop-selector' === $block->parsed_block['attrs']['namespace'] && ! empty( $block->context['query']['include'] ) ) { $query['post__in'] = $block->context['query']['include']; } return $query; } This reply was modified 2 years, 2 months ago by Creative Andrew . While working on this I noticed a couple of things. The query_loop_block_query_vars filter’s $block param doesn’t pass the variation itself. So it’s not possible to check 'creativeandrew/single-post-query-loop-selector' === $block->parsed_block['attrs']['namespace'] That might explain why in the documentation it is mentioned the need to have access to the pre_render_block . I was able to avoid my filter from being applied to other queries by comparing the queryId from the one coming from the pre_render_block and query_loop_block_query_vars function pre_render_block( $pre_render, $parsed_block ) { if ( isset( $parsed_block['attrs']['namespace'] ) && 'creativeandrew/single-post-query-loop-selector' === $parsed_block['attrs']['namespace'] ) { add_filter( 'query_loop_block_query_vars', function ( $default_query, $block ) use ( $parsed_block ) { if ( isset( $parsed_block['attrs']['query']['include'] ) && isset( $block->context['queryId'] ) && $block->context['queryId'] === $parsed_block['attrs']['queryId'] ) { $default_query['post__in'] = $parsed_block['attrs']['query']['include']; } return $default_query; }, 10, 2 ); } return $pre_render; } This reply was modified 2 years, 2 months ago by Creative Andrew . This reply was modified 2 years, 2 months ago by Creative Andrew . This reply was modified 2 years, 2 months ago by Creative Andrew . Problem fixed in latest version

Comments

5 shown
Willy Bahuaud 2024-03-19T13:50:00+00:00

Sorry, wrong code… updated here: add_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\filter_my_query', 10, 2 ); function filter_my_query( $query, $block ) { if ( ! empty( $block->context['query']['include'] ) ) { $query['post__in'] = $block->context['query']['include']; } return $query; }

Creative Andrew 2024-03-28T21:44:00+00:00

Hi Willy , Thanks a lot for your message. Yes, this was reported here as well: https://github.com/creative-andrew/single-post-query-loop-selector/issues/1 I will be amending the code shortly and submitting a new release!

Creative Andrew 2024-03-28T21:58:00+00:00

However, wouldn’t it be better to do: add_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\filter_my_query', 10, 2 ); function filter_my_query( $query, $block ) { if ( isset( $block->parsed_block['attrs']['namespace'] ) && 'creativeandrew/single-post-query-loop-selector' === $block->parsed_block['attrs']['namespace'] && ! empty( $block->context['query']['include'] ) ) { $query['post__in'] = $block->context['query']['include']; } return $query; } This reply was modified 2 years, 2 months ago by Creative Andrew .

Creative Andrew 2024-03-29T08:52:00+00:00

While working on this I noticed a couple of things. The query_loop_block_query_vars filter’s $block param doesn’t pass the variation itself. So it’s not possible to check 'creativeandrew/single-post-query-loop-selector' === $block->parsed_block['attrs']['namespace'] That might explain why in the documentation it is mentioned the need to have access to the pre_render_block . I was able to avoid my filter from being applied to other queries by comparing the queryId from the one coming from the pre_render_block and query_loop_block_query_vars function pre_render_block( $pre_render, $parsed_block ) { if ( isset( $parsed_block['attrs']['namespace'] ) && 'creativeandrew/single-post-query-loop-selector' === $parsed_block['attrs']['namespace'] ) { add_filter( 'query_loop_block_query_vars', function ( $default_query, $block ) use ( $parsed_block ) { if ( isset( $parsed_block['attrs']['query']['include'] ) && isset( $block->context['queryId'] ) && $block->context['queryId'] === $parsed_block['attrs']['queryId'] ) { $default_query['post__in'] = $parsed_block['attrs']['query']['include']; } return $default_query; }, 10, 2 ); } return $pre_render; } This reply was modified 2 years, 2 months ago by Creative Andrew . This reply was modified 2 years, 2 months ago by Creative Andrew . This reply was modified 2 years, 2 months ago by Creative Andrew .

Creative Andrew 2024-03-29T10:02:00+00:00

Problem fixed in latest version