【问题标题】:wp_insert_post does not insert string with apostrophes correctlywp_insert_post 没有正确插入带撇号的字符串
【发布时间】:2014-06-03 05:08:40
【问题描述】:

我正在编写的脚本中使用 wp_insert_post(出于多种原因),它会导致其中包含撇号的任何字符串被截断为该字符(包括该字符)。这是我必须测试的代码:

$question = "If you’re in need, this is who you call";

echo $question."<br />";

$post = array(
    'post_title'     => $question,
    'post_status'    => 'publish',
    'post_type'      => 'question'
);  

echo $post['post_title'];

$the_post_id = wp_insert_post($post);

这很奇怪,因为当我回显两个字符串时,两端都回显了正确的内容,因此我将其隔离到导致问题的 wp_insert_post 函数。当我在 WordPress 中查看时,标题只是“如果你”,然后结束。

我在这里发现了类似的问题:

http://premium.wpmudev.org/forums/topic/q-wp_insert_post-truncates-post-content-on-quotes-is-there-a-proper-way-to-escape-these-things

但该页面上似乎没有任何解决方案。关于这里发生了什么以及如何解决它的任何想法?不知道为什么会导致它。我正在查看它是否与我的代码中的其他内容有关,但它似乎不应该因为数组元素在 wp_insert_post() 函数之前回显时似乎格式化得很好。

感谢您的帮助!

【问题讨论】:

    标签: php arrays wordpress foreach


    【解决方案1】:

    用像&amp;acute;这样的html 5符号替换撇号并尝试存储这对我有用。

    【讨论】:

      【解决方案2】:
          $my_post = array(
                 'post_title'    => 'My post',
                 'post_content'  => 'This is my post.',
                 'post_status'   => 'publish',
                 'post_author'   => 1,
                 'post_category' => array(8,39)
                 );
      
                    // Insert the post into the database
                       wp_insert_post( $my_post );
      

      【讨论】:

        猜你喜欢
        • 2011-05-12
        • 1970-01-01
        • 1970-01-01
        • 2021-03-09
        • 1970-01-01
        • 1970-01-01
        • 2019-05-28
        • 1970-01-01
        • 2011-10-06
        相关资源
        最近更新 更多