dutchigor/cmb2-rest-query 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dutchigor/cmb2-rest-query

Composer 安装命令:

composer require dutchigor/cmb2-rest-query

包简介

Adds a query parameter to the REST API for any CMB2 field that has the property rest_query set on it.

README 文档

README

Adds a query parameter to the REST API for any CMB2 field that has the property rest_query set on it.

How to install

Option one

  • Clone or download and unzip this plugin in to your WordPress plugin directory and active.

Option two

  • Add dutchigor/cmb2-rest-query to required packages in composer and require CMB2-rest-query.php in your code

How to use

Setting up the metabox in CMB2

Add the query_rest property to the field that you wish to query by in your CMB2 field configuration.

  • If set to true, the field ID will used to query the REST API.
  • If set to a value, the value will be used to query REST API.

Example

$cmb = new_cmb2_box( [
    'id'            => 'my_metabox',
    'title'         => __( 'My Metabox', 'cmb2' ),
    'object_types'  => [ 'post' ],
    'show_in_rest'  => WP_REST_Server::ALLMETHODS
] );

$cmb->add_field( [
    'id'            => 'my_text_field',
    'name'          => 'My text field',
    'type'          => 'text',
    'rest_query'    => true
] );

$cmb->add_field( [
    'id'            => 'custom_query_name',
    'name'          => 'My text field',
    'type'          => 'text',
    'rest_query'    => 'my_query'
] );

Querying the REST API

For each field that has rest_query set, 3 parameters will be available in the REST request on each post type that this field's metabox is registered on:

  • the field's rest_query value or id (as defined above)
  • the above parameter appended with _compare
  • the above parameter appended with _type

Adding the field's query parameter to the request will add that field to the request's meta query. By default compare will be '=' but using the {rest_query}_compare parameter, this can be changed to any option allowed by WP_Meta_Query. The type of the query parameter will be set to 'CHAR' by default but this can be overwritten using {rest_query}_type, again with the values allowd in WP_Meta_Query.

Following the above example a query could look like:

const request = new Request('https://wordpress.org/wp-json/wp/v2/posts?my_text_field=hello&my_query=world&my_query_compare=LIKE');

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-03-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固