I'm new to Wordpress and php,so sorry for my basic question. I want to add some posts in a category programmatically. For example every day i want to select some posts and insert them into a category with php code and for next day replace some other posts. Is it possible? How? Thanks in advance.
2 Answers
You can use wp_insert_post
https://codex.wordpress.org/Function_Reference/wp_insert_post
See the Codex, here you have a lot of examples:
// 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 );
To update the Post see wp_update_post
https://codex.wordpress.org/Function_Reference/wp_update_post
-
I don't want to insert new post to database. i just want to add posts that exist in database to category programmatically. May 2, 2014 at 18:55
-
wp_set_post_categories( $post_id, array( 1, 2 ) );
-
If i set new category for my post, can i return it to previous category? for example i want, when a user visit my site, put some posts in a category and when user leave my site, posts return to previous category. May 6, 2014 at 17:50
-
-
Because i'm using Post Rating plugin for scoring posts and also my theme should get a category for showing on slider. and i want to show most rating posts on slider. what should i do? :( May 7, 2014 at 14:32