0

I'm doing some custom coding and creating a new page template to use for a new page within Wordpress. I'm trying to add a meta box to the page to be displayed as output to the user. I tried to do the following in my page template:

add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' );

When I go to the URL to display the new page I created I get the following error message: Fatal error: Call to undefined function get_current_screen() in D:\My Documents\xampp_new\xampp\htdocs\bmt\wp-admin\includes\template.php on line 921

How can I add meta boxes to be displayed to an end user?

2
  • I want to say that Metaboxes were designed for admin-panel / backend use only but maybe somebody here has a solution for you.
    – Howdy_McGee
    Commented Jan 13, 2015 at 19:41
  • @Howdy_McGee No, you're right, meta boxes were designed for the admin area of the site. You'd display the post meta info that you save using a meta box, on the front end.
    – darrinb
    Commented Jan 13, 2015 at 22:07

1 Answer 1

0

By default WordPress doesn't load admin classes/function definitions in the front end of the site. You need to explicitly require the files.

As far as I remember requiring wp-admin/includes/admin.php would get you most of typical stuff.

4
  • I got rid of the original error by including this file. I did however get another one. I'm still using this code: add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core' ); The error message I'm getting now is: Warning: array_keys() expects parameter 1 to be array, null given in D:\My Documents\xampp_new\xampp\htdocs\bmt\wp-admin\includes\plugin.php on line 1676 Warning: Invalid argument supplied for foreach() in D:\My Documents\xampp_new\xampp\htdocs\bmt\wp-admin\includes\plugin.php on line 1676 Commented Jan 14, 2015 at 15:37
  • Actually only including that file on my page creates that warning. Commented Jan 14, 2015 at 15:44
  • It's hard to tell because there is no loop at that line in current WP version (4.1).
    – Rarst
    Commented Jan 14, 2015 at 15:50
  • Ok, I guess I'll just have to code this portion by myself. Thanks. Commented Jan 14, 2015 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.