繁体   English   中英

在Wordpress中添加类别-自定义

[英]Adding category in wordpress - custom

// Auto post ( Unique File Date ).
$postData = array(
    'post_category' => array( '0' ),
    'post_status' => $Post_Status,
    'post_type' => $Post_Type,
    'post_date' => $File_Individual_Date
);
wp_insert_post( $postData );

当使用'post_category' => array( '0' ), ,它将在Uncategorised类别下添加帖子。 如果我在var中有一个类别怎么办:

$myCategory = 'News' ;

然后使用'post_category' => $myCategory给出错误,并且没有添加新帖子。 是否可以通过这种方式添加类别?

检查文档中的wp_insert_post

post_category应该是类别ID的数组,因此您需要为您的变量分配类别ID的数组才能起作用

尝试$myCategory = array('News');

UPD: 以防万一

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM