0

Here is an example of a function that is triggered once a post "reservation" has been created :

function new_reserv()
{

       $args = array( 'post_type' => 'reservations', 'posts_per_page' => 10 );

       $loop = new WP_Query( $args );

       while ( $loop->have_posts() ) : $loop->the_post();


               // DO some action


       endwhile;
}

add_action( 'publish_reservations', 'new_reserv');

So, the problem is that when creating the FIRST post "reservation", with the hook "publish" the variable "$loop" is empty, i.e, this hook does not allow to work on the post one just created.

Anyone knows a way to retrieve posts' infos as soon as it get created ?

Thank you

0
add_action('save_post_reservations', 'new_reserv');
function new_reserv($post_id){
    // $post_id - just created post id
}
  • Please edit your answer, and add an explanation: why could that solve the problem? – fuxia Sep 5 '17 at 13:25

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.