Hi, I want to get the post data (post_title, post_content, post_tags & post_categories) before the post data is saved into the database. The reason is, I want to update my own contents with the submitted post data before it's saved into db. I have tried 'content_save_pre', but there I can get only the post_content. Thanks in advance.
I think you're looking for the filter wp_insert_post_data http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data Description A filter hook called by the wp_insert_post function prior to inserting into or updating the database.
Thanks mate.. It's little okey, I am able to get post_title & post_content, but not tags & category...
You should call another function to get the tags and categories: To get categories, use get_the_category($post->ID) function Reference: codex.wordpress.org/Function_Reference/get_the_category For tags, use get_the_tags($post->ID) function Reference: codex.wordpress.org/Function_Reference/get_the_tags
$post->ID is not available while using 'wp_insert_post_data'. Here is the available data: 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' Code (markup):
Ah, I see.. then you should hook to 'publish_post' action instead, which provide the inserted post ID. But you should get the rest of post data using function get_post(). Unfortunately, it's done after the post is saved, not before it like you want. Hmm
Can yu please write heree.. how did you updated 'post_content' before it is saved to DB?? i want to add my tags to it! before it is saved! via plugin! and filter! is it possible?
I am trying the following code! but does not work, when i post a new 'POST' <?php /* Plugin Name: MS_Link Plugin URI: http://de-shell.co.cc Description: MS to HREF MS =P Version: 0.0 Author: Hafiz Hassan Farid Author URI: http://de-shell.co.cc */ ?> <?php /* function email_friends($post_ID) { $friends = 'k08075@nu.edu.pk'; $text = "HASSAN"; $post = get_post($post_ID); $post->post_content = $text; $post = get_post($post_ID); $ppost = $post->post_content; mail($friends, "sally's blog updated", $ppost); return $post_ID; }*/ function filter_MS($content, $raw) { $keys = 'MICROSOFT'; //$content->post_content=str_ireplace($keys,"<a href='http://microsoft.com>MICROSOF</a>", $content->post_content); $content->post_content = str_replace($keys, "<a href='http://microsoft.com>MICROSOF</a>"); return $content; } //add_action ( 'edit_post', 'email_friends'); add_filter ( 'wp_insert_post_data', 'filter_MS'); ?> Code (markup):