I can't get the toggle state and open/close status of meta_boxes on my plugin admin page to be stored. The ajax response is always 0

I'm using meta boxes to hold sections of menu for a plugin.

wp_enqueue_script( 'common' );
wp_enqueue_script( 'wp-lists' );
wp_enqueue_script( 'postbox' );

are called on an init add_action hook

add_meta_boxes are called with admin_menu add_action hook Then the admin page for my plugin is rendered thus...

<div class="wrap" id="church-admin">
<div id="icon-index" class="icon32"><br/></div><h2>Church Admin Plugin</h2>
<div id="poststuff">
    <!-- #post-body .metabox-holder goes here -->
    <div id="post-body" class="metabox-holder columns-2">
        <!-- meta box containers here -->
        <form style="display:none" method="get" action="">
            <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
            <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>
        <?php do_meta_boxes('church-admin','advanced',null);?>
<script type="text/javascript">
            postboxes.add_postbox_toggles( pagenow );

Why are opn/close toggles and order changes not saved?

  • Why are your meta-boxes outside the form? – s_ha_dum Mar 22 '13 at 13:55
  • No good reason! Removed style="display:none" from form tag and closed the form tag after do_meta_boxes. Can still toggle and close, but it's not saved! BTW the scripts are in the footer for some unknown reason! – andymoyle Mar 22 '13 at 14:04
  • Try adding wp_enqueue_script( 'post' );, and are you sure your scripts are enqueueing correctly? – s_ha_dum Mar 22 '13 at 14:11
  • Yes - toggles and order change still work, but aren't remembered on page refresh still – andymoyle Mar 22 '13 at 14:24
  • Can't answer my own question - but changing the jquery did the trick. postboxes.add_postbox_toggles( 'church-admin'); church-admin is the name of my plugin. That made it work. – andymoyle Mar 22 '13 at 15:10

To get the save to work the postboxes.add_postbox_toggles( pagenow ); needs to be replaced with

postboxes.add_postbox_toggles( 'pluginname' );

In my case postboxes.add_postbox_toggles( 'church-admin' );

I've blogged a how to using meta boxes on plugin admin pages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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