I'm looking for a solution to a bug that occured in an answer to an earlier question.

The general idea is that I want to invoke submit on the post form and have the page published. What happens now is that the page reloads and the message "Page updated" appears, however the page is not published and not even drafted.

I've created a small demo to drop into your functions.php to test it out. In the demo I've created a secondary publish button that you can use to experience the problem, this is merely for illustration purposes, in the real case submit is invoked via ajax.

add_action('add_meta_boxes', 'add_metaboxes_pages', 10, 2);
function add_metaboxes_pages($post_type, $post)
    add_meta_box('pagesubmitdiv', 'WPSE_DEMO_META_BOX', 'page_submit_meta_box', 'page', 'advanced', 'low');

function page_submit_meta_box($post) 
    <a id="secondary-publish" class="button-primary">Secondary Publish</a><?php

add_action( 'admin_head-post.php', 'wpse_publish_admin_hook' );
add_action( 'admin_head-post-new.php', 'wpse_publish_admin_hook' );
function wpse_publish_admin_hook()
    global $current_screen;
    if( 'page' != $current_screen->post_type )

    <script language="javascript" type="text/javascript">
        jQuery(document).ready(function() {

Trigger the click event of the publish button instead, and let WP do the work.

    jQuery(document).ready(function( $ ) {
        $( "#secondary-publish" ).click(function () {
             $( "#publish" ).click()

Don't use language (it was deprecated in HTML 4.01!) - you can drop type too (WP now has an HTML5 doctype).

  • Thanks for your reply (and your corrections). It works as it should standalone, but when I implent it in where it's gonna be used it produces a loop. Hm, do you have an idea what I could do? pastebin.com/RBZq842m – INT Nov 8 '12 at 11:47
  • How did I miss that! See update. – TheDeadMedic Nov 8 '12 at 11:48
  • The problem is that I only have #publish in the real example, #secondary-publish was just something I used in this demo for illustration purposes (so it wouldn't collide with wp original publish meta box). In the real example you actually push #publish and there's a check via ajax and then it's supposed to published, so #publish is gonna get pressed indefinitely. It's all there in the pastebin in my last comment. – INT Nov 8 '12 at 12:04
  • Solved it by having a secondary button like my example and having the original publish button hidden. Thanks for your help! – INT Nov 11 '12 at 23:03

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.