Post Sub-title with REST API

Home Forums Legacy Support Support queries How-to & Troubleshooting Post Sub-title with REST API

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #62870
    Juippi
    Spectator
    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?  
    #62930
    Juippi
    Spectator
    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 ); }
    #62942
    H.K. Latiyan
    Participant
    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.
Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Post Sub-title with REST API’ is closed to new replies.