Monday 7 December 2009

How to do automated posting in wordpress?

To Post Anything on WordPress I am providing you knowledge of DB structure of wordpress tables if you can insert these records in respective table, you are done, you can post just by firing SQL queries. Now it is your choice to call that SQL from Java, PHP or Perl or whatever way it suits you.

There are 4 Major Tables responsible for this.

1. Wp_terms

2. Wp_term_taxonomy

3. Wp_term_relationships

4. Wp_post

Problem: You want to make a post in certain category (c1) with few tags (t1 and t2)

Solutions:

Step 1:

First check for category c1 exist in wp_terms of not

If exist get the id, go to wp_terms_taxonomy, increase the count by 1

If not exist insert the category c1 in wp_terms and for that id, make an entry in wp_term_taxonomy with count=1, and new term_id(which has just got created), taxonomy = ‘category’

So in both the case you’ll be getting wp_term_taxonomy_id.

Do the same for tags t1 and t2 as well, and you’ll be getting wp_term_taxonomy ids for them

Step2:

Make a new entry in wp_post,

· post_author can be fixed, find the id from wp_users, will be 1 if there is only 1 user

· post_status = publish (revision post status is inherit)

· comment_status=open

· ping_status=open

· post_password=’’

· post_name=unique value of (title and using -, and digits)

· post_type=post (for draft and all, it is revision)

Step3:

You have to make entry in wp_term_relationship

Object_id = post_id

Term_taxonomy_id=id of wp_term_taxonomy table (the value we got in step 1)

You’ll have to make two more entries in wp_term_relationship

Same object_id and term_taxonomy_id that we got from tags(t1 and t2) in step 1

Done :)

For reference use this link: http://codex.wordpress.org/Database_Description