Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9060337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:12:12+00:00 2026-06-16T15:12:12+00:00

Good morning, I need a hook or something to call to separate new posts

  • 0

Good morning,
I need a hook or something to call to separate new posts from updated ones.

I want to execute some code only for new posts… something like that:

add_action('publish_post', myfunction);

function myfunction( $post_id ){
    if <new post> {
        /* do something */
    }
    else {
        /* do nothing */
    }
}

I’m using WP v3.5

Any suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:12:13+00:00Added an answer on June 16, 2026 at 3:12 pm

    First, you want to use the draft_to_publish hook:

    add_action('draft_to_published', 'my_function');
    

    However, this can fire multiple times if a post is published, unpublished, and then published again. To ensure that your action only fires one time, set a custom meta element for the post at the end of your function. At the start of your function, check if you meta element is set and skip the action if it is.

    — Added —

    Here is a sample on how the repeat action protection would work (untested code – so might need a little work):

    function my_function() {
        $already_done = get_post_meta($post_id, 'do_once', true);
        if(!$already_done) {
            // Do what you need to do here
            add_post_meta($post_id, 'do_once', 1, true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want
So, I'd like to be able to make a call x = MyClass.new('good morning',
Good morning! I need to move data from Oracle 8i(Enterprise Edition Release 8.1.6.0.0) to
Good morning, I am in need of some advice, I am using a networkStream,
Good morning, everyone. I need some query help. You can assume I understand relatively
Good morning, At the moment I am needing some help from someone more experienced
good morning. We need to copy tables from Access to SQL. Thing is the
Good morning. I've been having this issue for some days and have been lokking
Good morning ! What is the best way to remove duplicate records from grid
Good Morning All! I have been developing a project for some time in which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.