2

I'm currently using a version of this function - post formats - how to switch meta boxes when changing format? which hides all meta boxes until a corresponding post format is selected (Ie; If someone selects "Video" then my custom Video meta box shows up)

But when the post is saved all the meta boxes become hidden again unless I reselect the post format.

Is there a way to show the appropriate meta box even when the post has been saved?

This is the main function;

jQuery( document ).ready( function($)
        {
            // Starts by hiding the "Video Options" meta box
            $( "#video-options" ).addClass( "hidden" );

            // If "Video" post format is selected, show the "Video Options" meta box
            $( "input#post-format-video" ).change( function() {
                $( "#video-options" ).removeClass( "hidden" );
            } );

        }
    );
1

Try this one:

jQuery( document ).ready( function($)
{
    // Starts by hiding the "Video Options" meta box
    $( "#video-options" ).addClass( "hidden" );

    if( $( "input#post-format-video" ).is(':checked') ){
        $( "#video-options" ).removeClass( "hidden" );
    }
    // If "Video" post format is selected, show the "Video Options" meta box
    $( "input#post-format-video" ).change( function() {
        if( $(this).is(':checked') ){
            $( "#video-options" ).removeClass( "hidden" );
        }
    } );

    }

);

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.