Save hooks not functioning correctly…
-
Could someone please take a look and tell me exactly why this is not behaving the way it should be?
What I am trying to achieve:
Have the information be saved whenever user saves, updates, or publishes their post.What’s actually happening:
It initially saves the data… but later on, when user makes multiple revisions, instead of updating the database record, it creates a new entry in the database table with revision ID as the post ID…the code:
add_action('save_post', 'add_save_process');
function add_save_process($post_ID) {
global $wpdb;$data = $_POST['data'];
// Make sure no duplicates...
$is_exists = $wpdb -> get_var("SELECT COUNT(*) FROM$wpdb->storageWHEREID= $post_ID”);
if ($is_exists) {
$wpdb->query( “UPDATE $wpdb->storage SET data = ‘”.$data.”‘ WHERE post_id = $post_ID” );
} else {
$wpdb->query( “INSERT INTO $wpdb->storage (post_id, data) VALUES ($post_ID, ‘”.$data.”‘)” );
}
} -
the code didn’t come out right… let’s try again
[code]
add_action('save_post', 'add_save_process');
function add_save_process($post_ID) {
global $wpdb;$data = $_POST['data'];
// Make sure no duplicates...
$is_exists = $wpdb -> get_var("SELECT COUNT(*) FROM$wpdb->storageWHEREID= $post_ID");
if ($is_exists) {
$wpdb->query( "UPDATE $wpdb->storage SET data = '".$data."' WHERE post_id = $post_ID" );
} else {
$wpdb->query( "INSERT INTO $wpdb->storage (post_id, data) VALUES ($post_ID, '".$data."')" );
}
}
[/code] -
i give up!
could a moderator please modify the above post to show the code in its entirety?
I tried both, < code > (without the space) and [code] tags to close my code within, but to no avail! -
nevermind. I figured it out.
here’s how to:
use wp_is_post_revision instead of using $post_ID… that should solve it!Thanks!
-
Sorry but you are in the wrong place. This is the support forum for WordPress.com users. Please seek help at http://wordpress.org/ .
- The topic ‘Save hooks not functioning correctly…’ is closed to new replies.