Wordpress add_meta_box() weirdness

后端 未结 3 852
眼角桃花
眼角桃花 2021-02-08 11:17

The code below is working nearly flawlessly, however my value for page title on one of my pages keeps coming up empty after a few page refreshes... It sticks for awhile, then it

相关标签:
3条回答
  • 2021-02-08 11:36

    The WordPress Codex has got an function reference for add_meta_box(), with a great example.

    And yes, it uses

    
     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
        return $post_id;
    

    and I think you've implemented it the right way.

    0 讨论(0)
  • 2021-02-08 11:37

    FYI, the solution posted here http://wordpress.org/support/topic/custom-post-type-information-disappearing worked for me and I think is much more elegant.

    0 讨论(0)
  • 2021-02-08 11:47

    Wordpress's auto save system may well be your problem, as I think custom fields are not passed along for auto saves (so your customHeader and customTitle post variables will be empty during an auto save).

    In your save function you should check if the DOING_AUTOSAVE constant is set (this seems to be preferable to checking the post action) and return if so. Something like this:

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
    

    See this ticket for more info: http://core.trac.wordpress.org/ticket/10744

    0 讨论(0)
提交回复
热议问题