How do i do something when a (normal) user creates a post (that is submitted for approval)

I currently have:

function emailinvestment( $new_status, $old_status, $post_id ) {

        if ( $old_status != 'new' && $new_status != 'pending' ) {

            // Do something (not working atm)


    add_action('transition_post_status','emailinvestment', 10,3);

Thanks for taking a look at this one :)

  • What doesn't work? Does the hook not fire at all? Are your conditions wrong (inside the if)? Does you code (not posted) inside the if not work? – s_ha_dum Sep 4 '13 at 14:52

If you want to target only one specific status change is probably easy / efficient use the {$old_status}_to_{$new_status} filter, in your case:

add_action('draft-to-pending', 'do_something');
add_action('auto-draft-to-pending', 'do_something');

function do_something ( $post ) {
  // do something with the $post object
  • For some reason the action does not fire at all using this method. – Cas Sep 5 '13 at 8:56
  • I have some doubts that actions don't fires... how have you debug that? Are you sure that the problem is not in your do_something function? – gmazzap Sep 5 '13 at 9:54
  • Got it working, check my own answer that has -1 :p – Cas Sep 5 '13 at 11:56
  • @CasvanDongen I don't now why your own answer got -1, and is reasonable that it works, but if it works my solution should work too, it only doesn't work if the post is setted to pending after be pubblished. However, if your solution work, mark it as accepted. – gmazzap Sep 5 '13 at 12:22
  • Can't mark it yet, i'll have to wait 24 hours before i can accept my own answer. Thanks :) – Cas Sep 5 '13 at 12:33

Found it! The following line:

if ( $old_status != 'new' && $new_status != 'pending' ) {

Should be:

if ( $old_status != 'new' && $new_status == 'pending' ) {

Thanks for the help guys!

  • Funny how this post gets a minus 1, i'm the topic starter and this code works lol – Cas Sep 5 '13 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.