Make WordPress Core


Ignore:
Timestamp:
06/29/2023 01:28:49 PM (15 months ago)
Author:
audrasjb
Message:

Editor: Allow Query Block to show posts from multiple selected authors.

This changeset adds handler for multiple cases where author data can be passed to the Query Block:

  • array: array of author ids
  • string: comma separated author ids
  • integer: single author id

Props adi3890, costdev, mayur8991, oglekler.
Fixes #58426.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r56064 r56109  
    13771377        }
    13781378        if (
    1379             isset( $block->context['query']['author'] ) &&
    1380             (int) $block->context['query']['author'] > 0
     1379            isset( $block->context['query']['author'] )
    13811380        ) {
    1382             $query['author'] = (int) $block->context['query']['author'];
     1381            if ( is_array( $block->context['query']['author'] ) ) {
     1382                $query['author__in'] = array_filter( array_map( 'intval', $block->context['query']['author'] ) );
     1383            } elseif ( is_string( $block->context['query']['author'] ) ) {
     1384                $query['author__in'] = array_filter( array_map( 'intval', explode( ',', $block->context['query']['author'] ) ) );
     1385            } elseif ( is_int( $block->context['query']['author'] ) && $block->context['query']['author'] > 0 ) {
     1386                $query['author'] = $block->context['query']['author'];
     1387            }
    13831388        }
    13841389        if ( ! empty( $block->context['query']['search'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.