WordPress“REST API"- 渲染 VisualComposer 内容 [英] WordPress "REST API" - Render VisualComposer Content

查看:32
本文介绍了WordPress“REST API"- 渲染 VisualComposer 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过REST API V2"插件从 WordPress 请求内容.这很好用.只剩下一个问题:VisualComposer"插件创建的内容不会在 de REST Response 中呈现.

回复是:

[vc_row]Hello World ...[/vc_row]

响应应该是:

Hello World ...</div>

这是怎么实现的??谢谢?

解决方案

我认为您可以在 WP REST API v2 中找到答案:https://github.com/WP-API/WP-API/issues/2578

下面的示例取自上面的链接(谢谢,bradmsmith!)

以下是如何在帖子内容上呈现 VC 短代码的示例:

add_action('rest_api_init', function(){register_rest_field(//如果您需要它与其他(甚至是自定义帖子)类型一起使用,//那么你必须使用一个数组://数组( 'page', 'post', 'custom_post_type', 'etc' )//这个例子只对 'page' 起作用//查看此答案第一个编辑部分中的链接'页','内容',大批('get_callback' =>'compasshb_do_shortcodes','update_callback' =>空值,'架构' =>空值,));});函数 compasshb_do_shortcodes( $object, $field_name, $request ){WPBMap::addAllMappedShortcodes();//这完成了所有的工作全球 $post;$post = get_post ($object['id']);$output['rendered'] = apply_filters('the_content', $post->post_content);返回 $output;}

编辑

这是 register_rest_field() 函数的链接:register_rest_field()

I'm requesting Content from WordPress by the "REST API V2" Plugin. This works great. There is just one problem left: Contents created by "VisualComposer" Plugin are not rendered in de REST Response.

Response is:

[vc_row]Hello World . . .[/vc_row]

Response should be:

<div class="row">Hello World . . .</div>

How can this be achieved?? Thank you?

解决方案

I think you can find your answer here with WP REST API v2: 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(
          // if you need it to work with other (even custom post) types,
          // then you have to use an array:
          // array( 'page', 'post', 'custom_post_type', 'etc' )
          // this example only does the trick for 'page'
          // look at the link in the first EDIT section of this answer
          '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;
}

EDIT

Here is the link for the register_rest_field() function: register_rest_field()

这篇关于WordPress“REST API"- 渲染 VisualComposer 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆