Make WordPress Core


Ignore:
Timestamp:
05/22/2023 10:01:07 AM (13 months ago)
Author:
spacedmonkey
Message:

Posts, Post Types: Add a new filter for query arguments in get_pages.

In [55569] get_pages was converted to use WP_Query internally. But for plugins that were extending the get_pages filters and filter WP_Query query arguments, this could result in a conflict. Add a filter get_pages_query_args to allow developers to change arguments passed to WP_Query but also have the context of the original arguments passed to the get_pages function.

This change also expands test coverage of get_pages to ensure no breakages in the future.

Props spacedmonkey, westonruter, costdev, flixos90, kenwins, marianne38.
See #12821.

File:
1 edited

Legend:

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

    r55743 r55845  
    60326032                    $post_author = $post_author->ID;
    60336033                }
    6034                 $query_args['author__in'][] = $post_author;
     6034                $query_args['author__in'][] = (int) $post_author;
    60356035            }
    60366036        }
     
    60606060        $query_args['posts_per_page'] = $number;
    60616061    }
     6062
     6063    /**
     6064     * Filters query arguments passed to WP_Query in get_pages.
     6065     *
     6066     * @since 6.3.0
     6067     *
     6068     * @param array $query_args  Array of arguments passed to WP_Query.
     6069     * @param array $parsed_args Array of get_pages() arguments.
     6070     */
     6071    $query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args );
    60626072
    60636073    $query = new WP_Query( $query_args );
Note: See TracChangeset for help on using the changeset viewer.