Support » Developing with WordPress » add_post_meta One Key with Multiple Values

Viewing 3 replies - 1 through 3 (of 3 total)
  • Resolved!

    I’ve pasted my solution here.

    What the problem was
    The hook save_post submits twice.

    While searching online I found out that save_post submits a regular post and a revision.

    Therefore, when I retrieved the post_type(i forgot what I used to do this) it was outputting “post, post”(i added the comma and space for clarity). This made things confusing because I was hoping to see something like “post, revision”(i added the comma and space for clarity).

    Therefore if I wanted to ignore the second post_type “revision” with some conditional statement, it would fail.

    The online forums mentioned wp_is_post_revision. However, for some reason a lot, I mean A LOT of people have developed a habit of not informing you how to use it with a simple example.

    How to use wp_is_post_revision within a conditional statement

    function ez_portfolio_gallery_save($post_ID){
            $ez_portfolio_gallery = $_POST['ez_portfolio_gallery'];
            //verify post is not a revision
            if ( !wp_is_post_revision( $post_ID ) ) {
                    add_post_meta($post_ID, 'ez_portfolio_gallery', $ez_portfolio_gallery);

    You don’t have to use the global $post; code (found in the pastebin). I was simply using that for debugging purposes.

    I hope this helps others!

    Thankyou luisleguisamo. This was just what I wanted to know. And the background too. Very clear and helpful. Many thanks.

    You’re welcome, conormaxwell! I’m glad it was helpful.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add_post_meta One Key with Multiple Values’ is closed to new replies.