簡體   English   中英

WP添加待處理帖子時不No

[英]WP No slug when adding a pending post

我正在使用以下代碼片段來添加帖子:

$post_args = array(
    'post_content'   => 'test test',
    'post_name'      => 'slughere',
    'post_title'     => 'title',
    'post_status'    => 'pending',
    'ping_status'    => 'closed',
    'comment_status' => 'closed'
);

$new_post_id = wp_insert_post( $post_args );

如果我添加狀態為“發布”的帖子,則可以使用。 但是當我將其發布為“待處理”帖子時,由於某種原因,並未添加該條目。 它只是空着。

有誰知道為什么會這樣嗎?

運行最新的WP,甚至再次更新內核,以確保那里沒有奇怪的事情發生。

如果您想手動添加參數post_name ,請確保清理並確保唯一性

因此,請嘗試以下代碼:-

$post_args = array(
        'post_content'   => 'test test',
        'post_name'   => wp_unique_post_slug( sanitize_title( 'slughere' ) ),
        'post_title'     => 'title',
        'post_status'    => 'pending',
        'ping_status'    => 'closed',
        'comment_status' => 'closed'
);

$new_post_id = wp_insert_post( $post_args );

希望這會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM