[英]WP_Insert_Post and GUID Issue [Wordpress]
I have a posting form at my theme. 我在主题上有一个发布表格。 I used wp_insert_post there.
我在那里使用了wp_insert_post。 My code looks like this
我的代码看起来像这样
$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);
Everything works fine. 一切正常。 But when it's inserted to the database, at the GUID field, the entry format is like this permalinks_structure/id.
但是当它插入数据库时,在GUID字段中,条目格式就像这个permalinks_structure / id。 So if my permalinks_structure is like /category/id , it become like http://www.example.com/uncategorized/1 .
因此,如果我的permalinks_structure类似于/ category / id,它就像http://www.example.com/uncategorized/1 。 So the problem is, if i post through wordpress admin panel, GUID of the post is http://www.example.com?p=1 .
所以问题是,如果我通过wordpress管理面板发帖,帖子的GUID是http://www.example.com?p=1 。 So my post database GUID become mess, because if i want to change permalinks_structure , the post which becomes from outside form will follow the structure.
所以我的帖子数据库GUID变得混乱,因为如果我想改变permalinks_structure,那么从外部形式变成的帖子将遵循结构。
What I want to do is, I want to get the GUID like that I posted through admin panel which is http://www.example.com?p=1 我想要做的是,我想获得像我通过管理面板发布的GUID http://www.example.com?p=1
How can i do it ? 我该怎么做 ? Please point me out.
请指出我。 Thank you.
谢谢。
I think the short answer is to not worry about the GUID of a post in WordPress. 我认为简短的回答是不要担心WordPress中的帖子的GUID。 Here's a thread discussing the (in)validity of a post's GUID: http://www.mail-archive.com/wp-testers@lists.automattic.com/msg12434.html
这是一个讨论帖子GUID(in)有效性的帖子: http : //www.mail-archive.com/wp-testers@lists.automattic.com/msg12434.html
If you ever need a post's URL, you should use the get_permalink() function. 如果你需要一个帖子的网址,你应该使用get_permalink()函数。 This will always respect your current permalink structure, and is the safest way to get post's URL
这将始终尊重您当前的固定链接结构,并且是获取帖子URL的最安全方式
Return # 回归#
(int|WP_Error) The post ID on success. (int | WP_Error)成功时的帖子ID。 The value 0 or WP_Error on failure.
失败时值0或WP_Error。
So .. check for integer and do this to get the URL $url = get_permalink($post_id); 所以..检查整数并执行此操作以获取URL $ url = get_permalink($ post_id);
This bypasses the direct call to the guid 这绕过了对guid的直接调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.