WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create an "admin only" meta box using WPAlchemy. The box for example may contain a "feature post" check box and other functionality.

How can I show this meta box for only the admin, yet have it work properly? I'm currently using the following code below, but I receive a "Fatal error: Call to a member function the_meta() on a non-object" when trying to echo the value of whatever is inside on the front-end. Everything works as intended if I don't use current_user_can and works also if I'm logged in as admin and viewing the front-end.

if (current_user_can('administrator')) {
$custom_admin_mb = new WPAlchemy_MetaBox(array(
    'id' => '_custom_admin_meta',
    'title' => 'Admin only',
    'template' => TEMPLATEPATH . '/custom/admin_meta.php',


share|improve this question
up vote 1 down vote accepted

try the following:

$custom_admin_mb = new WPAlchemy_MetaBox(array(
    'id' => '_custom_admin_meta',
    'title' => 'Admin only',
    'template' => get_stylesheet_directory() . '/custom/admin_meta.php',
    'output_filter' => 'my_output_filter',

function my_output_filter() {
    if (current_user_can('administrator')) return true;
    return false;
share|improve this answer
Thanks Dimas, Worked a treat! I also learnt about get_stylesheet_directory() - did not know that you could use that instead of TEMPLATEPATH. – Andrew Jul 5 '11 at 1:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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