Changeset 59115 for trunk/src/wp-includes/blocks.php
- Timestamp:
- 09/30/2024 01:17:40 AM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r59101 r59115 2336 2336 * @since 5.8.0 2337 2337 * @since 6.1.0 Added `query_loop_block_query_vars` filter and `parents` support in query. 2338 * @since 6.7.0 Added support for the `format` property in query. 2338 2339 * 2339 2340 * @param WP_Block $block Block instance. … … 2348 2349 'orderby' => 'date', 2349 2350 'post__not_in' => array(), 2351 'tax_query' => array(), 2350 2352 ); 2351 2353 … … 2397 2399 // Migrate `categoryIds` and `tagIds` to `tax_query` for backwards compatibility. 2398 2400 if ( ! empty( $block->context['query']['categoryIds'] ) || ! empty( $block->context['query']['tagIds'] ) ) { 2399 $tax_query = array();2401 $tax_query_back_compat = array(); 2400 2402 if ( ! empty( $block->context['query']['categoryIds'] ) ) { 2401 $tax_query [] = array(2403 $tax_query_back_compat[] = array( 2402 2404 'taxonomy' => 'category', 2403 2405 'terms' => array_filter( array_map( 'intval', $block->context['query']['categoryIds'] ) ), … … 2406 2408 } 2407 2409 if ( ! empty( $block->context['query']['tagIds'] ) ) { 2408 $tax_query [] = array(2410 $tax_query_back_compat[] = array( 2409 2411 'taxonomy' => 'post_tag', 2410 2412 'terms' => array_filter( array_map( 'intval', $block->context['query']['tagIds'] ) ), … … 2412 2414 ); 2413 2415 } 2414 $query['tax_query'] = $tax_query;2416 $query['tax_query'] = array_merge( $query['tax_query'], $tax_query_back_compat ); 2415 2417 } 2416 2418 if ( ! empty( $block->context['query']['taxQuery'] ) ) { 2417 $ query['tax_query']= array();2419 $tax_query = array(); 2418 2420 foreach ( $block->context['query']['taxQuery'] as $taxonomy => $terms ) { 2419 2421 if ( is_taxonomy_viewable( $taxonomy ) && ! empty( $terms ) ) { 2420 $ query['tax_query'][] = array(2422 $tax_query[] = array( 2421 2423 'taxonomy' => $taxonomy, 2422 2424 'terms' => array_filter( array_map( 'intval', $terms ) ), … … 2425 2427 } 2426 2428 } 2427 } 2429 $query['tax_query'] = array_merge( $query['tax_query'], $tax_query ); 2430 } 2431 if ( ! empty( $block->context['query']['format'] ) && is_array( $block->context['query']['format'] ) ) { 2432 $formats = $block->context['query']['format']; 2433 /* 2434 * Validate that the format is either `standard` or a supported post format. 2435 * - First, add `standard` to the array of valid formats. 2436 * - Then, remove any invalid formats. 2437 */ 2438 $valid_formats = array_merge( array( 'standard' ), get_post_format_slugs() ); 2439 $formats = array_intersect( $formats, $valid_formats ); 2440 2441 /* 2442 * The relation needs to be set to `OR` since the request can contain 2443 * two separate conditions. The user may be querying for items that have 2444 * either the `standard` format or a specific format. 2445 */ 2446 $formats_query = array( 'relation' => 'OR' ); 2447 2448 /* 2449 * The default post format, `standard`, is not stored in the database. 2450 * If `standard` is part of the request, the query needs to exclude all post items that 2451 * have a format assigned. 2452 */ 2453 if ( in_array( 'standard', $formats, true ) ) { 2454 $formats_query[] = array( 2455 'taxonomy' => 'post_format', 2456 'field' => 'slug', 2457 'operator' => 'NOT EXISTS', 2458 ); 2459 // Remove the `standard` format, since it cannot be queried. 2460 unset( $formats[ array_search( 'standard', $formats, true ) ] ); 2461 } 2462 // Add any remaining formats to the formats query. 2463 if ( ! empty( $formats ) ) { 2464 // Add the `post-format-` prefix. 2465 $terms = array_map( 2466 static function ( $format ) { 2467 return "post-format-$format"; 2468 }, 2469 $formats 2470 ); 2471 $formats_query[] = array( 2472 'taxonomy' => 'post_format', 2473 'field' => 'slug', 2474 'terms' => $terms, 2475 'operator' => 'IN', 2476 ); 2477 } 2478 2479 /* 2480 * Add `$formats_query` to `$query`, as long as it contains more than one key: 2481 * If `$formats_query` only contains the initial `relation` key, there are no valid formats to query, 2482 * and the query should not be modified. 2483 */ 2484 if ( count( $formats_query ) > 1 ) { 2485 // Enable filtering by both post formats and other taxonomies by combining them with `AND`. 2486 if ( empty( $query['tax_query'] ) ) { 2487 $query['tax_query'] = $formats_query; 2488 } else { 2489 $query['tax_query'] = array( 2490 'relation' => 'AND', 2491 $query['tax_query'], 2492 $formats_query, 2493 ); 2494 } 2495 } 2496 } 2497 2428 2498 if ( 2429 2499 isset( $block->context['query']['order'] ) &&
Note: See TracChangeset
for help on using the changeset viewer.