The easiest solution is to use jQuery
. Add the below code to any JS file that you include in the admin area.
As you haven’t given very much information above I don’t know a couple of things, so you’ll need to amend this example slightly –
-
Change
your-post-type
to the slug of the post type for which this metabox exists. If it’s the default Post then it’ll just bepost
. -
Change
'#field-name'
to the correct ID of your field. To find this out, check the source of your page.
The code –
jQuery(document).ready(function($){
var post_type = $('#post_type').val();
if(post_type === 'your-post-type'){
$('input#publish').on('click', function(e){
var myVal = $('#field-name').val();
if(yourMetaField === ''){
e.preventDefault();
alert('You must fill all meta box value before save post');
}
});
}
});