2016-08-04 67 views
1

我對我在哪裏取結果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); 
} 
} 
?> 
+0

你可以試試'strip_shortcodes()'和由WordPress提供了這個功能。 –

+0

@Rocky strip_shortcodes()沒有工作,已經嘗試過 –

+2

你試過了嗎?正則表達式'的preg_replace( 「〜(?:?:\ [/?)[^/\] +/\] - 的」, '',$ the_content);' –

回答

1

在這裏,你可以嘗試,並很容易地在你需要陣列添加一些短代碼,你也可以通過下面的代碼刪除所有簡碼。

$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()

+0

現在這段代碼工作 str_replace('[vc_column_inner width =「1/3" ]」, '',的preg_replace( 「〜(?:[?/)[^/\]?\] +/\]〜的」, '',$寶> POST_CONTENT)) 實際上有vc_column中的不同參數,所以如果他們來了,我會用str_replace刪除它們。你的答案會有所幫助。我會upvote它,但它不是準確的解決方案 –

+0

看看我已經更新的代碼也參數無關短代碼,這個正則表達式只檢查你已經在數組中使用的短碼。你可以運行這個代碼,然後在數組中傳遞'VC_COLUMN_INNTER',然後它接受內容中的參數。 –

+0

是啊,它的工作原理,謝謝 –

相關問題