WP_Insert_Post和GUID问题[Wordpress]

时间:2010-04-28 03:55:11

标签: php wordpress

我的主题是张贴表格。我在那里使用了wp_insert_post。我的代码看起来像这样

$post = array(
      'ID' => '',
      'post_author' => $post_author,
      'post_category' => $post_category,
      'post_content' => $post_content,
      'post_title' => $post_title,
      'post_status' => 'publish',
    );  

    $post_id = wp_insert_post($post);
    $fullpost = get_post($post_id);

    wp_redirect($fullpost->guid);

一切正常。但是当它插入数据库时​​,在GUID字段中,条目格式就像这个permalinks_structure / id。因此,如果我的permalinks_structure类似于/ category / id,它就像http://www.example.com/uncategorized/1。所以问题是,如果我通过wordpress管理面板发帖,帖子的GUID是http://www.example.com?p=1。所以我的帖子数据库GUID变得混乱​​,因为如果我想改变permalinks_structure,那么从外部形式变成的帖子将遵循结构。

我想要做的是,我希望得到像我通过管理面板发布的GUID http://www.example.com?p=1

我该怎么办?请指出我。谢谢。

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

返回#

(int | WP_Error)成功时的帖子ID。失败时值0或WP_Error。

所以..检查整数并执行此操作以获取URL $ url = get_permalink($ post_id);

这绕过了直接调用guid

相关问题