Support » Plugins » Conditional add_meta_box using get_post_meta($post->ID,'_wp_page_template', true

Viewing 2 replies - 1 through 2 (of 2 total)
  • I now understant hy this didn’t work:

    if (get_post_meta($post->ID,'_wp_page_template', true) == 'mbizpa.php')
      add_action( 'admin_init', 'myplugin_add_custom_box', 1 );
      add_action( 'save_post', 'myplugin_save_postdata' );

    $post->ID is not set to any value.

    I think i’ve found my solution here:

    How to Limit the Display of a WordPress Meta Box

    Instead of doing a get_post_meta to get the post ID, I can get it with the following code:

    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;

    But, I still don’t understand why $post->ID doesn’t give me anything at the begining of my plugin, but later in the same plugin, I use it to display, and it works perfectly.

    Thanks again.


    You probably didn’t define $post as a global variable in your plugin’s function.

    function foo(){
    global $post;
    [Your code involving $post]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditional add_meta_box using get_post_meta($post->ID,'_wp_page_template', true’ is closed to new replies.