Created
July 10, 2018 06:30
-
-
Save daniloparrajr/6b8f9313aa30c24f294562e4c1311500 to your computer and use it in GitHub Desktop.
Wordpress Adding Custom Post Type on WP REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment