Hide meta box based on post format

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.

Read More

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

        }
    );

Related posts

Leave a Reply

1 comment

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

    );