WordPress.org

Ready to get started?Download WordPress

Forums

Functions.php not recognizing add_meta_box (7 posts)

  1. Lindquist
    Member
    Posted 4 years ago #

    I upgraded to 3.0 this morning and decided to experiment with the new custom post types and custom meta boxes. The custom post types have gone great, but I am having a hard time getting the meta boxes to show up.

    A few minutes ago I found what I think is the cause of all my problems, but I don't know why it's happening. I did a simple if/else with function_exists( 'add_meta_box') and it's coming back false.

    Is there a reason why WordPress would not be recognizing this function?

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    None that I know of. All I can suggest is that you try this using the Twentyten theme with all plugins deactivated in case something else is causing a problem.

  3. wmeredith_kc
    Member
    Posted 4 years ago #

    I'm having the same problem, even with all plugins turned off. Code is below:

    add_action('init', 'wpv_custom_post_types');
    function wpv_custom_post_types() {
    	$labels = array(
    	'name' => _x('Cards', 'post type general name'),
    	'singular_name' => _x('Card', 'post type singular name'),
    	'add_new' => _x('Add New', 'card'),
    	'add_new_item' => __('Add New Card'),
    	'edit_item' => __('Edit Card'),
    	'new_item' => __('New Card'),
    	'view_item' => __('View Card'),
    	'search_items' => __('Search Cards'),
    	'not_found' =>  __('No cards found'),
    	'not_found_in_trash' => __('No cards found in Trash'),
    	'parent_item_colon' => ''
    	);
    	$args = array(
    	'labels' => $labels,
    	'public' => true,
    	'publicly_queryable' => false,
    	'show_ui' => true,
    	'query_var' => true,
    	'rewrite' => true,
    	'capability_type' => 'post',
    	'hierarchical' => false,
    	'menu_position' => null,
    	'supports' => array('title','editor','author','thumbnail')
    
    	);
    	register_post_type('card',$args);
    };
    add_meta_box('wpv_custom_post_types','Card Options','wpv_custom_post_types','card','side','low');
  4. Lampe
    Member
    Posted 4 years ago #

    I have exactly the same problem. Is there no solution so far?
    Error message:
    Fatal error: Call to undefined function add_meta_box() in /www/htdocs/w00cccaf/wordpress/wp-content/themes/twentyten/functions.php on line 584

  5. jacobdubail
    Member
    Posted 4 years ago #

    I have the exact same problem, too. I just get a blank screen in the admin backend.

  6. jacobdubail
    Member
    Posted 4 years ago #

    I just figured it out. This code works as either a plugin or in your functions.php:

    add_action('init', 'jtd_custom_post_types');
    function jtd_custom_post_types() {
    	$labels = array(
    	'name' => _x('Cards', 'post type general name'),
    	'singular_name' => _x('Card', 'post type singular name'),
    	'add_new' => _x('Add New', 'card'),
    	'add_new_item' => __('Add New Card'),
    	'edit_item' => __('Edit Card'),
    	'new_item' => __('New Card'),
    	'view_item' => __('View Card'),
    	'search_items' => __('Search Cards'),
    	'not_found' =>  __('No cards found'),
    	'not_found_in_trash' => __('No cards found in Trash'),
    	'parent_item_colon' => ''
    	);
    	$args = array(
    	'labels' => $labels,
    	'menu_position' => 30,
    	'public' => true,
    	'query_var' => true,
    	'supports' => array( 'title', 'editor', 'comments', 'revisions', 'author', 'excerpt', 'custom-fields', 'page-attributes', 'thumbnail' ),
    	'rewrite' => array( 'slug' => 'provider', 'with_front' => false ),
    	'taxonomies' => array( 'post_tag', 'category'),
    
    	);
    	register_post_type('card',$args);
    };
    
    // This function tells WP to add a new "meta box"
    function add_some_box() {
    	add_meta_box(
    		'ozh', // id of the <div> we'll add
    		'My Box', //title
    		'add_something_in_the_box', // callback function that will echo the box content
    		'card' // where to add the box: on "post", "page", or "link" page
    	);
    }
    // This function echoes the content of our meta box
    function add_something_in_the_box() {
    	echo "I'm living in a box";
    }
    // Hook things in, late enough so that add_meta_box() is defined
    if (is_admin())
    	add_action('admin_menu', 'add_some_box');
  7. sgelbart
    Member
    Posted 3 years ago #

    Thanks! Worked perfectly.

Topic Closed

This topic has been closed to new replies.

About this Topic