php Wordpress在WP REST API上添加自定义帖子类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Wordpress在WP REST API上添加自定义帖子类型相关的知识,希望对你有一定的参考价值。
<?php
/**
* Add WCC contest details into the WP Rest API
*
* @param [class] $object Query Object.
* @return string Contest details.
*/
function get_wcc_contest_details( $object ) {
$wcc_contest_details = get_post_meta( $object['id'], '_wcc_contest_details', true );
return rest_ensure_response( $wcc_contest_details );
}
/**
* Register custom rest api fields
*
* @return void
*/
function mxc_wcc_contest_details() {
register_rest_field( 'wcc_contest', 'wcc_contest_price', array(
'get_callback' => 'get_wcc_contest_price',
'schema' => array(
'description' => __( 'Contest Price' ),
'type' => 'text',
),
) );
}
add_action( 'rest_api_init', 'mxc_wcc_contest_details' );
以上是关于php Wordpress在WP REST API上添加自定义帖子类型的主要内容,如果未能解决你的问题,请参考以下文章