WordPress 6.2 引入 search_columns 参数来控制在搜索查询中搜索哪些字段

以前,WP_Query::parse_query()方法的s参数搜索post_titlepost_excerpt, 和post_content字段,除了使用posts_search过滤器和手动调整 SQL外,无法控制这一点。

WordPress 6.2 添加了使用search_columns参数指定在执行查询时搜索哪些字段的功能。

目前,只允许使用默认的 post_titlepost_excerptpost_content 列,但它可能会在 WordPress 的后续版本中得到扩展。

search_columns 参数的默认值为:array( 'post_title', 'post_excerpt', 'post_content' )

下面的示例将搜索在其摘要(post_excerp列)中包含 foo 的帖子,排除post_titlepost_content列。

 'foo',
        'post_type'      => 'post',
        'search_columns' => array( 'post_excerpt' ),
    )
);

要了解更多信息,请查看这里

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注