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 Answer
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" );
        }
    } );

    }

);

Leave a Reply

Your email address will not be published. Required fields are marked *