Support » Fixing WordPress » Adding extra option on post /page meta box

  • Hi,

    I am trying to add a tick box option to a page / post in an existing metabox.

    The featured image box is ideal as the option I want relates to the featured image and the featured image box has a filter to add html

    // adds tick option to featured image
    function add_tick_option($content) {
       global $post;
       $meta = get_post_meta($post->ID, 'myoption', true);
       $input = '<br><input type="checkbox" name="myoption" id="myoption"' . ( $meta ? ' checked="checked"' : '' ) . ' /><br />My Text';
       return  $content . $input ;

    This code works fine EXCEPT after the addtion or removal of the featured image. The html for this metabox if redisplayed in its entirety after the image change (obviously to display / hide the featured image). The problem is in this call the global $post is nullified so whatever setting in the tick box that had been made gets lost.

    Is there anyway around this? Or should I be looking at filtering a different metabox? I don’t want to create a standalone metabox for one tick box.


  • The topic ‘Adding extra option on post /page meta box’ is closed to new replies.