Rearranging Dashboard meta boxes with use of plugin/functions.php

add_meta_box has a the following placement parameters: $context ‘normal’, ‘advanced’, ‘side’ $priority ‘high’, ‘core’, ‘default’ ‘low’ For $context the difference between normal and advanced is that normal will be placed on the page before advanced. The $priority determines the hierarchy but is overridden when dragged by the user. You can disable the drag and drop … Read more

Automatically assign taxonomy term if custom meta value exists

You should hook onto the save_post action. add_action( ‘save_post’, ‘add_video_taxonomy’ ); function add_video_taxonomy( $post_id ) { // you should check if the current user can do this, probably against publish_posts // you should also have a nonce check here as well if( get_post_meta( $post_id, ‘video_url’, true ) ) { wp_set_post_terms( $post_id, ‘video’, ‘your_custom_taxonomy_name’, true ); … Read more

Post.php – Conditional statements for new post and edit post

edit.php is the post/page list, the post creation/editing screen are 2 separate files: post-new.php and post.php. so you can target using “load-$page” hook, e.g.: add_action( ‘load-post.php’, function() { // add metabox or whatever you want when EDITING post add_action( ‘add_meta_boxes’, ‘myplugin_meta_box_editing’ ); } ); add_action( ‘load-post-new.php’, function() { // add metabox or whatever you want … Read more

Adding Metaboxes – so much code is there a shorter DRY way?

Leverage Functions You can extract the redundant code into reusable functions. For example, the last two functions could be rewritten like this. My resulting code is actually 2 lines longer, but it’s much cleaner from a debugging standpoint. And, if there were a third custom field, this approach would definitely be shorter. function slidestoshow_save_post_meta_box( $post_id, … Read more

Custom Post Type Meta Boxes

Change advanced to normal, this will at least move it up above some others. However, there’s no guarantee you get the top spot, because a user can still drag and drop metaboxes around, or a core metabox or one added by another plugin might believe it is more important than yours. There’s no way for … Read more

MetaBox Layout for all users

You could setup a different default layout by hooking into do_meta_boxes, take a look here: How to change default position of WP meta boxes? Or you could use the global variable $wp_meta_boxes to do so: Get List of Registered Meta Boxes and Removing Them How to Remove Certain Screen Options and Meta Boxes from add/edit … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)