How to Get visual composer page through rest api

2019-08-02 06:09发布

问题:

I'm developing an ionic app in which I have a rest api to get the blog contents from wordpress page. I'm trying to get the visual composer page through api but I'm getting raw html format and css or missing for visual component pages. Can I get the visual composer page fully along the properties through api or is there any restriction to use api ??

回答1:

I think you find your answer here: https://github.com/WP-API/WP-API/issues/2578

The example below was taken from the link above (thank you, bradmsmith!)

Here is an example how to render the VC shortcodes on the content of a post:

add_action( 'rest_api_init', function ()
{
   register_rest_field(
          'page',
          'content',
          array(
                 'get_callback'    => 'compasshb_do_shortcodes',
                 'update_callback' => null,
                 'schema'          => null,
          )
       );
});

function compasshb_do_shortcodes( $object, $field_name, $request )
{
   WPBMap::addAllMappedShortcodes(); // This does all the work

   global $post;
   $post = get_post ($object['id']);
   $output['rendered'] = apply_filters( 'the_content', $post->post_content );

   return $output;
}