How can I insert a message into wordpress and associate it with a category?

I have content from other sources that I would like to insert as a publication in Wordpress, and then link to an existing category. It is very simple to insert a new record into the wp_posts table, but I cannot figure out how to build a query to insert a new record and at the same time associate the message with the category. How can this be done?

If this helps, I use WordPress 2.8

+5
source share
4 answers

Use this query:

INSERT INTO wp_posts (post_title,post_content,post_name,post_date,post_date_gmt,post_modified,post_modified_gmt,post_author,post_status) 
VALUES ('title','text','post_name',now(),now(),now(),now(),1,'publish')

INSERT INTO wp_term_relationships (object_id,term_taxonomy_id) VALUES ([the_id_of_above_post],1)
+14
source

use the wp_insert_post function, then use the wp_set_post_categories function

http://codex.wordpress.org/Function_Reference

+5

wp_terms wp_posts wp_terms, wp_term_relationships table.

, wp_posts, , , wp_term_relationships.

: WordPress

+4

All Articles