Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php strip_短代码不起作用_Php_Wordpress_Function - Fatal编程技术网

Php strip_短代码不起作用

Php strip_短代码不起作用,php,wordpress,function,Php,Wordpress,Function,我是Wordpress的初学者,我正在尝试从数据库中删除帖子内容中的所有短代码。我找到了为wordpress创建的名为strip_shortcodes的函数,但我真的不知道如何使用它。我在网上看了看,我仍然不知道哪里是我的错误 代码如下: $all_pages = $wpdb->get_results ( "SELECT * FROM " . $post_table . " WHERE post_type = 'page' " ); foreach ($all_pages as

我是Wordpress的初学者,我正在尝试从数据库中删除帖子内容中的所有短代码。我找到了为wordpress创建的名为strip_shortcodes的函数,但我真的不知道如何使用它。我在网上看了看,我仍然不知道哪里是我的错误

代码如下:

$all_pages = $wpdb->get_results (
    "SELECT * FROM " . $post_table . " WHERE post_type = 'page' "
);

foreach ($all_pages as $page) {
    echo '<h1>' . $page->post_title . '</h1>';
    $content = $page->post_content;
    echo strip_shortcodes($content) . PHP_EOL;
}
结果:

[间隔尺寸=5][tabs style=1][tab title=Définition][heading 边框=cf3549颜色=444444样式=1]Qu'est-ce Qu'un hébergement 网状物[heading]我的位置是每年一次 维修人员,在机器安装位置安装设备 含糊是一种无系统的语言 利用传统通信Windows和Mac。系统 对自由逻辑关系的服务开发 comme Linux,nginx ou des logiciels payants comme Windows服务器。乐 serveur web n'est que la partie matérielle hardware,qu'il faut 与互补性相对应的系统开发耦合器, 这是partie logicielle软件

例外结果:

你是说什么?我的位置很好 服务人员的工作时间和地点 这是一种模糊的语言,它是一种语言 无系统开发传统通信Windows和Mac。女同性恋 逻辑逻辑关系服务开发系统 libres comme Linux,nginx ou des logiciels payants comme Windows 服务器服务商网站是一家专业的硬件供应商, 与之对应的开发系统的故障连接器 compétences,这是partie logicielle软件


有人能告诉我问题出在哪里吗?

您的代码看起来不错,但在数据库中保存时却丢失了。回声的输出是什么? 我会这样做,未经测试:

$all_pages = $wpdb->get_results ( "SELECT * FROM " . $post_table . " WHERE post_type = 'page' " ); foreach ($all_pages as $key => $page) { $all_pages[$key]->post_content = strip_shortcodes($page->post_content); // Save the content to the database wp_update_post($all_pages[$key]); } 查看帖子“主页”时,去掉所有短代码,但在其他页面(如single.php)上,不要去掉短代码

单击此处了解更多详细信息:和

试试这个删除快捷码的功能可能会有帮助


试试这个

它显示了什么,预期的输出是什么不要紧,我编辑了它谢谢你的回答,没有办法从一个不在帖子主页的内容中删除短代码?@Exprator给你正确的答案。我觉得有一个好方法。WC@CédricCosson。这个方法非常有效,但是我无法在functions.php中的元描述生成器中使用strip_短代码函数来剥离短代码。
function remove_shortcode_from_index( $content ) {
  if ( is_home() ) {
    $content = strip_shortcodes( $content );
  }
  return $content;
}
add_filter( 'the_content', 'remove_shortcode_from_index' );
            $content = preg_replace('#\[[^\]]+\]#', '',$page->post_content);
            echo apply_filters('the_content', $content);