new post hook (7 posts)

  1. stuk88
    Posted 6 years ago #

    Hi every body.
    im trying to write a plugin that will count for any user new posts when added,
    but i saw just post_publish hook that is activated on post send and on post published status change.
    is there a hook for just "new post"?
    or is there any way to check if the post published is new or just new to be published?

  2. popper
    Posted 6 years ago #

    Have you checked here? It's a pretty complete guide.

  3. stuk88
    Posted 6 years ago #

    yup already checked there...
    i didnt able to find any "new_post" like, hook.

  4. stuk88
    Posted 6 years ago #

    There is any way to hook to a new post creation?

  5. popper
    Posted 6 years ago #

    save_post Runs whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. Action function arguments: post ID.

  6. stuk88
    Posted 6 years ago #

    yea i know that didnt help me in the first time either..
    my quastion was how to check if the saved post was a new post or just an update to an exiting post...

    I already found a way to check this...
    new post doesnt have any id set to it yet.
    so the code looks like that:
    if($post->post_parent == 0 && $post->post_type == 'post' && !$post->ID)

    i had to do some other check on deleted post either, because the "delete_post" hook run whenever a post data deleted... page or post or revision...

  7. kif0rt
    Posted 5 years ago #

    I'm using the next code to handle the first time post publish event.
    WordPress 3.0+ required.

    add_action( 'publish_post', 'run_when_post_published_first_time',10,2 );
    function run_when_post_published_first_time($post_id, $post)
    // Checks whether is post updated or published at first time.
    if ($post->post_date != $post->post_modified) return;

    // Place here your code

    P.S. Sorry for my english.

Topic Closed

This topic has been closed to new replies.

About this Topic