S
S
sportik1742021-08-15 14:37:13
PHP
sportik174, 2021-08-15 14:37:13

How to execute code when adding a new Wordpress post?

Hello!
How to execute the code when creating a new post?

Now mine looks like this:

add_action( 'save_post_news', 'wpdocs_notify_subscribers', 10, 3);
 
function wpdocs_notify_subscribers( $post_id, $post, $update ) {
 
  
    if ( $update ) {
        return;
    }
  
    // Здесь выполняю код
}


But the code is executed both when creating and when deleting, and even when I go to the edit page

I can’t understand what is the reason

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Alyoshin, 2021-08-15
@ArchitectOfRuin

Try instead of save_post_news to put save_post_post or just save_post and check how it will work in this case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question