Make WordPress Core


Ignore:
Timestamp:
02/07/2023 08:53:01 AM (13 months ago)
Author:
audrasjb
Message:

Query: Add a search_columns argument to control which fields are searched in a search query.

Previously, the s argument of the WP_Query::parse_query() method searched the post_title, post_excerpt, and post_content fields, with no way of controlling this apart from using the posts_search filter and adjusting the SQL manually. This changeset adds the ability to specify which fields are searched when performing a query, using the search_columns argument.

Props johnbillion, birgire, petitphp, audrasjb, costdev, mukesh27.
Fixes #43867.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r54870 r55248  
    250250            'parent_exclude' => 'post_parent__not_in',
    251251            'search'         => 's',
     252            'search_columns' => 'search_columns',
    252253            'slug'           => 'post_name__in',
    253254            'status'         => 'post_status',
     
    28922893        }
    28932894
     2895        $query_params['search_columns'] = array(
     2896            'default'     => array(),
     2897            'description' => __( 'Array of column names to be searched.' ),
     2898            'type'        => 'array',
     2899            'items'       => array(
     2900                'enum' => array( 'post_title', 'post_content', 'post_excerpt' ),
     2901                'type' => 'string',
     2902            ),
     2903        );
     2904
    28942905        $query_params['slug'] = array(
    28952906            'description' => __( 'Limit result set to posts with one or more specific slugs.' ),
Note: See TracChangeset for help on using the changeset viewer.