: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
} elseif ( 'id=>name' === $_fields ) {
foreach ( $term_objects as $term ) {
$_terms[ $term->term_id ] = $term->name;
} elseif ( 'id=>slug' === $_fields ) {
foreach ( $term_objects as $term ) {
$_terms[ $term->term_id ] = $term->slug;
} elseif ( 'all' === $_fields || 'all_with_object_id' === $_fields ) {
* Generate the ORDER BY clause for an 'orderby' param that is potentially related to a meta query.
* @param string $orderby_raw Raw 'orderby' value passed to WP_Term_Query.
* @return string ORDER BY clause.
protected function parse_orderby_meta( $orderby_raw ) {
// Tell the meta query to generate its SQL, so we have access to table aliases.
$this->meta_query->get_sql( 'term', 't', 'term_id' );
$meta_clauses = $this->meta_query->get_clauses();
if ( ! $meta_clauses || ! $orderby_raw ) {
$primary_meta_key = null;
$primary_meta_query = reset( $meta_clauses );
if ( ! empty( $primary_meta_query['key'] ) ) {
$primary_meta_key = $primary_meta_query['key'];
$allowed_keys[] = $primary_meta_key;
$allowed_keys[] = 'meta_value';
$allowed_keys[] = 'meta_value_num';
$allowed_keys = array_merge( $allowed_keys, array_keys( $meta_clauses ) );
if ( ! in_array( $orderby_raw, $allowed_keys, true ) ) {
switch ( $orderby_raw ) {
if ( ! empty( $primary_meta_query['type'] ) ) {
$orderby = "CAST({$primary_meta_query['alias']}.meta_value AS {$primary_meta_query['cast']})";
$orderby = "{$primary_meta_query['alias']}.meta_value";
$orderby = "{$primary_meta_query['alias']}.meta_value+0";
if ( array_key_exists( $orderby_raw, $meta_clauses ) ) {
// $orderby corresponds to a meta_query clause.
$meta_clause = $meta_clauses[ $orderby_raw ];
$orderby = "CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})";
* Parse an 'order' query variable and cast it to ASC or DESC as necessary.
* @param string $order The 'order' query variable.
* @return string The sanitized 'order' query variable.
protected function parse_order( $order ) {
if ( ! is_string( $order ) || empty( $order ) ) {
if ( 'ASC' === strtoupper( $order ) ) {
* Used internally to generate a SQL string related to the 'search' parameter.
* @global wpdb $wpdb WordPress database abstraction object.
* @param string $search Search string.
* @return string Search SQL.
protected function get_search_sql( $search ) {
$like = '%' . $wpdb->esc_like( $search ) . '%';
return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like );
* Creates an array of term objects from an array of term IDs.
* Also discards invalid term objects.
* @param Object[]|int[] $terms List of objects or term ids.
* @return WP_Term[] Array of `WP_Term` objects.
protected function populate_terms( $terms ) {
if ( ! is_array( $terms ) ) {
foreach ( $terms as $key => $term_data ) {
if ( is_object( $term_data ) && property_exists( $term_data, 'term_id' ) ) {
$term = get_term( $term_data->term_id );
if ( property_exists( $term_data, 'object_id' ) ) {
$term->object_id = (int) $term_data->object_id;
if ( property_exists( $term_data, 'count' ) ) {
$term->count = (int) $term_data->count;
$term = get_term( $term_data );
if ( $term instanceof WP_Term ) {
$term_objects[ $key ] = $term;
* @global wpdb $wpdb WordPress database abstraction object.
* @param array $args WP_Term_Query arguments.
* @param string $sql SQL statement.
* @return string Cache key.
protected function generate_cache_key( array $args, $sql ) {
// $args can be anything. Only use the args defined in defaults to compute the key.
$cache_args = wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) );
unset( $cache_args['cache_results'], $cache_args['update_term_meta_cache'] );
if ( 'count' !== $args['fields'] && 'all_with_object_id' !== $args['fields'] ) {
$cache_args['fields'] = 'all';
$taxonomies = (array) $args['taxonomy'];
// Replace wpdb placeholder in the SQL statement used by the cache key.
$sql = $wpdb->remove_placeholder_escape( $sql );
$key = md5( serialize( $cache_args ) . serialize( $taxonomies ) . $sql );
$last_changed = wp_cache_get_last_changed( 'terms' );
return "get_terms:$key:$last_changed";