Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ); ?>
        </form>
        <?php do_meta_boxes('church-admin','advanced',null);?>
    </div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($){$(".if-js-closed").removeClass("if-js-closed").addClass("closed");
            postboxes.add_postbox_toggles( pagenow );
            });
</script>

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

share|improve this question
    
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

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

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.