this hook should normally be triggered on new post but it doesn’t work
add_action("new_to_publish", "doSomething", 10,1);
function doSomething($post){
global $post;
$_SESSION['yeni'] = 'test';
}
echo $_SESSION['yeni'];
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
When you create a new post, the initial post status is not new, but rather auto-draft. Try this:
add_action("draft_to_publish", "doSomething", 10,1);
function doSomething($post){
global $post;
$_SESSION['yeni'] = 'test';
}
echo $_SESSION['yeni'];
Also note that you may want to make sure your session is properly initialized. To verify the callback works at least, enable WP_DEBUG and WP_DEBUG_LOG and do something like
add_action("draft_to_publish", "doSomething", 10,1);
function doSomething($post){
error_log( 'Inside the new post transition');
}
Then publish a post and look at wp-content/debug.log
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0