最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - CPT issue: Warning: call_user_func_array() expects parameter 1 to be a valid callback

programmeradmin0浏览0评论

I'm getting an error on the admin screen for the custom post type. I've searched lots of other answers but see nothing in my code that could be causing it. Here's my code. Any help would be greatly appreciated.

// Register the post types and taxonomys
add_action('init', 'register_post_types');
function register_post_types(){ 
// Property Post Type
$labels = array(
    'name'               => __('Properties'),
    'singular_name'      => __('Property'),
    'add_new'            => __('Add New'),
    'add_new_item'       => __('Add New Property'),
    'edit_item'          => __('Edit Property'),
    'new_item'           => __('New Property'),
    'view_item'          => __('View Property'),
    'search_items'       => __('Search Properties'),
    'not_found'          => __('Nothing found'),
    'not_found_in_trash' => __('Nothing found in Trash'),
    'parent_item_colon'  => '',
);

$args = array(
    'labels'               => $labels,
    'public'               => true,
    'publicly_queryable'   => true,
    'show_ui'              => true,
    'register_meta_box_cb' => 'custom_meta_boxes',
    'query_var'            => true,
    'menu_icon'            => null,
    'rewrite'              => true,
    'capability_type'      => 'post',
    'hierarchical'         => false,
    'menu_position'        => 5,
    'supports' => array( 'title', 'editor', 'genesis-seo', 'thumbnail','genesis-cpt-archives-settings' ),
    'has_archive' => true,
); 

register_post_type('property' , $args);

// Property Taxonomy
$taxononmy_args = array(
    'hierarchical'   => true, 
    'label'          => "Categories", 
    'singular_label' => "Category", 
    'rewrite'        => true,
    'show_admin_column' => TRUE
);

register_taxonomy("property_categories", array("property"), $taxononmy_args);
}

I'm getting an error on the admin screen for the custom post type. I've searched lots of other answers but see nothing in my code that could be causing it. Here's my code. Any help would be greatly appreciated.

// Register the post types and taxonomys
add_action('init', 'register_post_types');
function register_post_types(){ 
// Property Post Type
$labels = array(
    'name'               => __('Properties'),
    'singular_name'      => __('Property'),
    'add_new'            => __('Add New'),
    'add_new_item'       => __('Add New Property'),
    'edit_item'          => __('Edit Property'),
    'new_item'           => __('New Property'),
    'view_item'          => __('View Property'),
    'search_items'       => __('Search Properties'),
    'not_found'          => __('Nothing found'),
    'not_found_in_trash' => __('Nothing found in Trash'),
    'parent_item_colon'  => '',
);

$args = array(
    'labels'               => $labels,
    'public'               => true,
    'publicly_queryable'   => true,
    'show_ui'              => true,
    'register_meta_box_cb' => 'custom_meta_boxes',
    'query_var'            => true,
    'menu_icon'            => null,
    'rewrite'              => true,
    'capability_type'      => 'post',
    'hierarchical'         => false,
    'menu_position'        => 5,
    'supports' => array( 'title', 'editor', 'genesis-seo', 'thumbnail','genesis-cpt-archives-settings' ),
    'has_archive' => true,
); 

register_post_type('property' , $args);

// Property Taxonomy
$taxononmy_args = array(
    'hierarchical'   => true, 
    'label'          => "Categories", 
    'singular_label' => "Category", 
    'rewrite'        => true,
    'show_admin_column' => TRUE
);

register_taxonomy("property_categories", array("property"), $taxononmy_args);
}
Share Improve this question edited Jul 13, 2017 at 16:42 kraftner 5,6281 gold badge29 silver badges46 bronze badges asked Jul 13, 2017 at 16:40 SddarterSddarter 213 bronze badges 8
  • Does the error give you a line number? If so, what line is it? – czerspalace Commented Jul 13, 2017 at 16:58
  • those are very generic names for your cpt and functions, also can you indent your function appropriatley? It's difficult to read – Tom J Nowell Commented Jul 13, 2017 at 16:58
  • I'm getting an error on the admin screen for the custom post type Is that the only screen you're seeing the error? If the error was part of registering post type (which is hooked to init), I'd expect that error anywhere. – hwl Commented Jul 13, 2017 at 17:00
  • Imho is this the reason for the error: function 'custom_meta_boxes' not found or invalid function name. ?! – Charles Commented Jul 13, 2017 at 17:35
  • Doesn't look like there's something wrong with your CPT declaration. Have you tried removing it? Does it make the error disappear? – Picard Commented Jul 13, 2017 at 19:24
 |  Show 3 more comments

2 Answers 2

Reset to default 1

I've removed the custom_meta_boxes. I don't have to have them and it solves the problem. I still don't understand why they were a problem, but if I can do without them I will.

I appreciate everyone's efforts.

Note: rolling back to 4.7 made no difference.

where is your custom_meta_boxes function where you are adding your meta boxes?

Please see this URL for creating a custom meta box for the custom post type. After adding this function your code will work fine.

发布评论

评论列表(0)

  1. 暂无评论