【发布时间】:2014-06-19 12:57:58
【问题描述】:
我是 Wordpress 和 php 的新手,很抱歉我的基本问题。 我想以编程方式在一个类别中添加一些帖子。 例如,每天我都想选择一些帖子并将它们插入到带有 php 代码的类别中,然后在第二天替换一些其他帖子。 可能吗?如何? 提前致谢。
【问题讨论】:
标签: php wordpress categories
我是 Wordpress 和 php 的新手,很抱歉我的基本问题。 我想以编程方式在一个类别中添加一些帖子。 例如,每天我都想选择一些帖子并将它们插入到带有 php 代码的类别中,然后在第二天替换一些其他帖子。 可能吗?如何? 提前致谢。
【问题讨论】:
标签: php wordpress categories
你可以使用wp_insert_posthttps://codex.wordpress.org/Function_Reference/wp_insert_post
查看 Codex,这里有很多例子:
// 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 ) );
【讨论】: