This repository was archived by the owner on Feb 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 66/**
77 * BlocksWpQuery query.
88 *
9- * Wrapper for WP Query with additonal helper methods.
9+ * Wrapper for WP Query with additional helper methods.
1010 * Allows query args to be set and parsed without doing running it, so that a cache can be used.
1111 *
1212 * @deprecated 2.5.0
@@ -24,6 +24,25 @@ class BlocksWpQuery extends WP_Query {
2424 public function __construct ( $ query = '' ) {
2525 if ( ! empty ( $ query ) ) {
2626 $ this ->init ();
27+
28+ // Remove current product from query to avoid infinite loops and out of memory issues.
29+ // That might happen if the store is using Gutenberg for product descriptions.
30+ // See https://github.com/woocommerce/woocommerce-blocks/issues/6416.
31+ global $ post ;
32+ if ( $ post && array_key_exists ( 'post__in ' , $ query ) && is_array ( $ query ['post__in ' ] ) ) {
33+ $ global_post_id = $ post ->ID ;
34+ $ filtered_post__in = array_filter (
35+ $ query ['post__in ' ],
36+ static function ( $ post_id ) use ( $ global_post_id ) {
37+ if ( $ global_post_id === $ post_id ) {
38+ return false ;
39+ }
40+ return true ;
41+ }
42+ );
43+ $ query ['post__in ' ] = $ filtered_post__in ;
44+ }
45+
2746 $ this ->query = wp_parse_args ( $ query );
2847 $ this ->query_vars = $ this ->query ;
2948 $ this ->parse_query_vars ();
You can’t perform that action at this time.
0 commit comments