如何去除所有视觉作曲家简码/从WordPress的的POST_CONTENT获取与自定义查询
我对我在哪里取结果WP_query()函数解析JSON格式的web服务(API)的工作标签。这将进一步在android应用程序中使用。 问题是我与查询得到的是通过视觉作曲家和整个内容组成的POST_CONTENT是在像如何去除所有视觉作曲家简码/从WordPress的的POST_CONTENT获取与自定义查询
[VC_ROW][/VC_ROW][VC_COLUMN]some text[/VC_COLUMN] etc.
我想删除/剥去内容所有这些简码和检索只有平原此类标签的形式来自它的文本。是否有任何视觉作曲家功能,通过它我可以做到这件事
<?php
require('../../../wp-load.php');
require_once(ABSPATH . 'wp-includes/functions.php');
require_once(ABSPATH . 'wp-includes/shortcodes.php');
header('Content-Type: application/json');
$post_name = $_REQUEST['page'];
if($post_name!=''){
if($post_name=='services') {
$args = array(
'post_parent' => $page['services']['id'],
'post_type' => 'page',
'post_status' => 'published'
);
$posts = get_children($args);
foreach($posts as $po){
$services_array[] = array('id'=>$po->ID,'title'=>$po->post_title,'image'=>get_post_meta($po->ID, 'webservice_page_image',true),'description'=>preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $po->post_content));
}
$post = array(
'status'=>'ok',
'services'=>$services_array
);
echo json_encode($post);
}
}
?>
在这里,你可以尝试,并很容易地在你需要阵列添加一些短代码,你也可以通过下面的代码删除所有简码。
$the_content = '[VC_ROW][VC_COLUMN]some text1[/VC_COLUMN] etc.[/VC_ROW][VC_COLUMN_INNTER width="1/3"][/VC_COLUMN_INNTER]';
$shortcode_tags = array('VC_COLUMN_INNTER');
$values = array_values($shortcode_tags);
$exclude_codes = implode('|', $values);
// strip all shortcodes but keep content
// $the_content = preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $the_content);
// strip all shortcodes except $exclude_codes and keep all content
$the_content = preg_replace("~(?:\[/?)(?!(?:$exclude_codes))[^/\]]+/?\]~s", '', $the_content);
echo $the_content;
你想保留一些简码,你不能使用strip_shortcodes()
。
现在这段代码工作 str_replace('[vc_column_inner width =“1/3" ]”, '',的preg_replace( “〜(?:[?/)[^/\]?\] +/\]〜的”, '',$宝> POST_CONTENT)) 实际上有vc_column中的不同参数,所以如果他们来了,我会用str_replace删除它们。你的答案会有所帮助。我会upvote它,但它不是准确的解决方案 –
看看我已经更新的代码也参数无关短代码,这个正则表达式只检查你已经在数组中使用的短码。你可以运行这个代码,然后在数组中传递'VC_COLUMN_INNTER',然后它接受内容中的参数。 –
是啊,它的工作原理,谢谢 –
你可以试试'strip_shortcodes()'和由WordPress提供了这个功能。 –
@Rocky strip_shortcodes()没有工作,已经尝试过 –
你试过了吗?正则表达式'的preg_replace( “〜(?:?:\ [/?)[^/\] +/\] - 的”, '',$ the_content);' –