PluginProbe
Filter Everything — WordPress & WooCommerce Filters / 1.9.7
Filter Everything — WordPress & WooCommerce Filters v1.9.7
1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2.2 1.9.2.1 trunk 1.2.1 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.1 1.4.4 1.4.5 1.4.8 1.4.9 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 All 52 releases
← All changes | src/Entities/PostMetaEntity.php +38 -0 1.9.2.11.9.7 View file →
@@ -10,9 +10,17 @@
10 10 {
11 11 use PostMetaTrait;
12 12
13 13 public $items = [];
14 + /**
15 + * Declared explicitly: assigned from the outside in
16 + * EntityManager::prepareEntitiesToDisplay(); dynamic properties are
17 + * deprecated since PHP 8.2.
18 + */
19 + public $items_sort = [];
14 20
21 + public $filter = [];
22 +
15 23 public $entityName = '';
16 24
17 25 public $excludedTerms = [];
18 26
@@ -168,8 +176,38 @@
168 176 if( $position !== false ){
169 177 unset( $this->items[$index]->posts[$position] );
170 178 }
171 179 }
180 + }
181 + }
182 +
183 + /**
184 + * Keep only posts that belong to the set universe (all queried posts of
185 + * the set), same as TaxonomyEntity does. Without this the raw meta lists
186 + * (e.g. _stock_status of ALL published products, including those excluded
187 + * from the catalog) leak into wpcFilterJsonData, and the client-side
188 + * recount shows inflated counters compared to the server-rendered ones.
189 + *
190 + * Term posts of "Used for Variations" meta keys legitimately contain
191 + * variation IDs which are absent from the parent-product universe, so a
192 + * post survives when it is in the universe OR in the universe expanded
193 + * to variation IDs.
194 + */
195 + $em = Container::instance()->getEntityManager();
196 + $allWpQueriedPostIds = $em->getAllSetWpQueriedPostIds( $setId );
197 +
198 + if ( ! empty( $allWpQueriedPostIds ) ) {
199 + $universe = array_flip( $allWpQueriedPostIds );
200 + $universe_variations = apply_filters( 'wpc_from_products_to_variations', $universe );
201 +
202 + foreach ( $this->items as $index => $term ) {
203 + $intersected_posts = [];
204 + foreach ( $term->posts as $post_id ) {
205 + if ( isset( $universe[ $post_id ] ) || isset( $universe_variations[ $post_id ] ) ) {
206 + $intersected_posts[] = $post_id;
207 + }
208 + }
209 + $this->items[ $index ]->posts = $intersected_posts;
172 210 }
173 211 }
174 212 }
175 213