I have some custom post meta being generated and am ready to add to a post’s meta. I know how to do this. However, save_post
causes a redirection after POST data has been sent. This means I am redirected to the dashboard and lose access to my POST data – therefore I cannot debug easily.
Currently I am using something like:
add_action('save_post', 'something_process');
function something_process() {
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
print_r($_POST);
}
Is there a way to easily debug this?
The best approach for me has been to use a function to log the values to wp-content/debug.log, lifted from http://fuelyourcoding.com/simple-debugging-with-wordpress:
Then use the function like this in your save_post hook:
Make sure that wp-content/debug.log is writable, and that you have debugging enabled in wp-config.php:
Method 1:
Method 2:
create log file (my_logs.txt) in a folder, where you use this code:
The best solution I’ve found so far is storing the
$_POST
in a session var for access later.First Approach:
Second Approach:
Third Approach:
Or take any browser add-ons for console logging
may one of three help..Good Luck
You could also save your debug messages in a WordPress option and show it as an admin message after the redirect.
I use this for a quick formatted output :