I am using the REST API to publish posts outside of WordPress, and have run into a problem where not all of my shortcodes are getting processed. Specifically, most of my plugins' shortcodes are getting processed but nothing from visual composer is getting converted to HTML. I find that if I var_dump my REST API's post data function on the front end of the WordPress site itself (blank theme, theme is literally 'var_dump this function'), the shortcodes for VC do get processed.
I am not sure what I am doing wrong here, but here is my code for the REST API return:
function return_page_single( WP_REST_Request $request ) {
$page_id = $request->get_param( 'page' );
$args = array(
'id' => $page_id,
'post_type' => 'page',
'posts_per_page' => 1
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
$page = $query->posts;
$page_content = $page[0]->post_content;
$page_content = apply_filters( 'the_content', $page_content );
$page_content = do_shortcode( $page_content );
$page[0]->post_content = $page_content;
$query_return['page'] = $page;
$query_return['query'] = $query->query;
}
wp_reset_postdata();
return $query_return;
}
If I dump the contents of my REST API result, I get shortcodes for VC but everything else processes.
If I place the following in my theme:
var_dump( return_page_single( $request ) );
I get the fully processed post content.
I don't have a live example as this is being developed internally but if it helps to troubleshoot I can probably set something up.
I am using the REST API to publish posts outside of WordPress, and have run into a problem where not all of my shortcodes are getting processed. Specifically, most of my plugins' shortcodes are getting processed but nothing from visual composer is getting converted to HTML. I find that if I var_dump my REST API's post data function on the front end of the WordPress site itself (blank theme, theme is literally 'var_dump this function'), the shortcodes for VC do get processed.
I am not sure what I am doing wrong here, but here is my code for the REST API return:
function return_page_single( WP_REST_Request $request ) {
$page_id = $request->get_param( 'page' );
$args = array(
'id' => $page_id,
'post_type' => 'page',
'posts_per_page' => 1
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
$page = $query->posts;
$page_content = $page[0]->post_content;
$page_content = apply_filters( 'the_content', $page_content );
$page_content = do_shortcode( $page_content );
$page[0]->post_content = $page_content;
$query_return['page'] = $page;
$query_return['query'] = $query->query;
}
wp_reset_postdata();
return $query_return;
}
If I dump the contents of my REST API result, I get shortcodes for VC but everything else processes.
If I place the following in my theme:
var_dump( return_page_single( $request ) );
I get the fully processed post content.
I don't have a live example as this is being developed internally but if it helps to troubleshoot I can probably set something up.
I guess that Visual Composer is not running the Rest API space, probably it's better contact the support of that plugin.
In any case you can see if you can execute the method of the visual composer plugin used for the shortcode and run in your code.
I finally found the answer after changing my google strategy, adding this to my 'get' function causes VC shortcodes to trigger:
if(class_exists('WPBMap') && method_exists('WPBMap', 'addAllMappedShortcodes')) {
WPBMap::addAllMappedShortcodes();
};