Hi,
I'm trying to make a REST API request to display a new article. However, I'm missing the Post sub-title.
I'm using:
jQuery.getJSON('/wp-json/wp/v2/posts', function(response){console.log(response);});
I get basically every other element that I need but not the sub-title. Any ideas how I can register that with the API?
Got it to work after digging through the WPLMS files and the API docs. For others who might be interested (in functions.php file):
add_action( 'rest_api_init', 'register_subtitle' );
function register_subtitle() {
register_rest_field( 'post',
'subtitle',
array(
'get_callback' => 'api_get_subtitle',
'update_callback' => null,
'schema' => null,
)
);
}
function api_get_subtitle( $object, $field_name, $request ) {
return get_post_meta( $object[ 'id' ], 'vibe_subtitle', true );
}
Thanks for sharing the information here.
If you are adding the code in the function.php file then please use a child theme say blank child theme and then add the code in the function.php file of child theme. Otherwise add the code in the wplms-customizer.php file present in the wplms customizer plugin, as this plugin is exclusively provided for customization purpose and is never updated so the customizations are safe here.