简体   繁体   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 );

when using 'post_category' => array( '0' ), , it adds a post under the category Uncategorised . 当使用'post_category' => array( '0' ), ,它将在Uncategorised类别下添加帖子。 What if I have a category in a var lets say: 如果我在var中有一个类别怎么办:

$myCategory = 'News' ; $myCategory = 'News' ;

then using 'post_category' => $myCategory gives error and no new post is added. 然后使用'post_category' => $myCategory给出错误,并且没有添加新帖子。 Is it possible to add categories in this way? 是否可以通过这种方式添加类别?

Check the docs for wp_insert_post 检查文档中的wp_insert_post

post_category should be an array of category ID's, so you would need to assign an array of category ID's to your variable for this to work post_category应该是类别ID的数组,因此您需要为您的变量分配类别ID的数组才能起作用

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

UPD: Just in case UPD: 以防万一

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

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