How to make a meta box field a requirement

You can use Javascript to create a first-line convenience warning, but that is not a secure solution. You will need to interrupt the post save to truly create a required field. function req_meta_wpse_96762($data){ $allow_pending = false; if (isset($_POST[‘meta’])) { foreach ($_POST[‘meta’] as $v) { if (‘your_required_key’ === $v[‘key’] && !empty($v[‘value’])) { $allow_pending = true; } … Read more

Modifying the main editor priority

The editor is hard-coded into the form. It isn’t inserted by add_meta_box. There is a hook called edit_form_after_title which you should be able to use though. Proof of concept: // use the action to create a place for your meta box function add_before_editor($post) { global $post; do_meta_boxes(‘post’, ‘pre_editor’, $post); } add_action(‘edit_form_after_title’,’add_before_editor’); // add a box … Read more

Getting jQuery sortable items in custom metabox

It’s a matter of wrapping the jQuery into document.ready, add a handler to the items and configure the sortable: add_action( ‘add_meta_boxes’, ‘metabox_wpse_66122’ ); function metabox_wpse_66122() { add_meta_box( ‘my_sortable’, __( ‘My Sortable’ ), ‘sortable_wpse_66122’, ‘post’ ); } function sortable_wpse_66122() { echo ‘<ul class=”sortable ui-sortable”>’; $posts = get_posts( array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => … Read more

How to insert Gallery shortcode to a meta box

That is a weird way to do it, shortcodes are really meant for inserting into the editor, if you want to program some functionality it’s better to go straight into the template/code itself. //check if post format is gallery type if ( has_post_format( ‘gallery’ ) { echo do_shortcode(”); }

Remove a plugin meta box from the dashboard

I found that this works: add_action(‘admin_init’, ‘rw_remove_dashboard_widgets’); function rw_remove_dashboard_widgets() { remove_meta_box(‘wpdm_dashboard_widget’, ‘dashboard’, ‘normal’); } I guess ‘admin_init’ is the key, so that it runs before the dashboard is loaded.

add_meta_box does not go ‘side’

This might be caused because you have tried to move your custom meta box to some place and WordPress respects the user’s ordering/positioning of these boxes. You can do as gmazzap has told because this will create a new user with blank preferences. Or you can login to your database, find DBPREFIX_usermeta (DBPREFIX is your … Read more

how to sanitize checkbox input?

Be sure to set the value in your markup. You should have. <input type=”checkbox” name=”changeposition” value=”yes” /> Then, I’d suggest using sanitize_key() to sanitize. Keys are used as internal identifiers. Lowercase alphanumeric characters, dashes and underscores are allowed. Think of the word yes, as a key. That’s what you’re expecting is a lowercase alphanumeric value. … Read more

Getting the ID of a meta box

Here’s what I would do in order to get the ID of the metabox, In the Dashboard where the meta boxed are located, open up the Screen Options tab on the upper right corner Open up your browser’s developer tool (ex: Chrome) Use the element selector () and select the checkbox label that is listed … Read more