2017-11-18 71 views
-1

我正在檢索這樣的wordpress單一職位。Wordpress獲得單一職位沒有簡碼

function getPost($data){ 
    $post = get_post($data['id']); 
    return $post; 
} 
add_action('rest_api_init', function ($server) { 
    $server->register_route('get-post', '/get-post/(?P<id>[\d]+)', array(
     'methods' => 'GET', 
     'callback' => 'getPost', 
    )); 
}); 

如何從帖子內容中刪除簡碼。

我試過這個,但沒有工作。

$post = get_post($data['id']); 
$post->post_content = strip_shortcodes($post->post_content); 
return $post; 

回答

0

if strip_shortcodes()函數不起作用,那麼它可能會幫助你。

$content = preg_replace('#\[[^\]]+\]#', '',$post->content); 
+0

我也試過這個,但是這也從帖子中刪除了一些其他的內容(一些帖子)。 –