我是Wordpress和php的新手,很抱歉我的基本问题。我想以编程方式在类别中添加一些帖子。例如,每天我想选择一些帖子,并将它们插入到带有php代码的类别中,并在第二天替换一些其他帖子。可能吗?怎么样?预先感谢。
您可以使用wp_insert_post
https://codex.wordpress.org/Function_Reference/wp_insert_post
请参阅食典,这里有很多示例:
// Create post object
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post );
要更新帖子,请参阅wp_update_post
https://codex.wordpress.org/Function_Reference/wp_update_post
wp_set_post_categories( $post_id, array( 1, 2 ) );