views:

39

answers:

2

Hi all

I need to create a function which is triggered when a new wordpress post is added to the posts table for a particular category.

The function will grab the title of the post and add it to a new table called 'newsites' whose fields are (postid, title, questions, users) which is already created.

The 'questions' and 'users' fields will be calculated using a separate function already created.

If the title of the post already exists it will update the record and if not it will add a new record.

Any ideas how I can do this and especially, how do I catch a new post being added.

Thanks

Jonathan

A: 

You need to create a MySQL Trigger which fires after insert on posts and checks the field for a matching category. It can then INSERT ON DUPLICATE UPDATE on newsites, assuming that title is a unique key (which ensures that the data is updated if it's already there).

Ian Gregory
+1  A: 

Look into the Wordpress Filter/Action API.

There are filters for when a post is published, updated and changed status. From there all you need to do is add a relevant add_filter, add_action code.

Littlejon