Best practices for meta box placement?

It is hard to declare best practices here. The placement depends on the content of the metabox: an editor field would be too narrow usually in the side column; two small checkboxes on the other hand will look lost in the main column. To understand where which box will be placed, let’s use a small … Read more

Add additional metafields based on value of select box

Create your metaboxes as you normally would, they will be visible by default. Then use js to hide the ones you dont want initially visible. Your code would look something like below. The example is for a checkbox, but you will get the idea how it works. if ( $(‘input#_cmb_metaboxid_1’).is(‘:checked’) ) { $(‘#metabox_id_2’).show(); } else … Read more

Query a Custom Post Type to another CPT via Metabox

You’ll want to create a standard metabox via the official APIs, how to do that is beyond this answer, what I’ll talk about is your dropdown. What you need to save is the Post ID of the building, so something like this pseudocode: <?php $current_building=….; ?> <select name=”….”> <?php $query = new WP_Query( array( ‘post_type’ … Read more

show title if one of post meta exist

I prefer below way, $fb = get_post_meta($post->ID, ‘ecpt_facebookpage’, true); $twitter = get_post_meta($post->ID, ‘ecpt_facebookpage’, true); //etc… if($fb != “” || $twitter != “” || $instagram = “”){ echo “Follow Us On”; if($fb != “”){ ?> <a target=”_blank” href=”http://www.facebook.com/<?php echo $fb; ?>”> <img src=”<?php bloginfo(‘template_url’); ?>/images2/service-fb.png” width=”25px” height=”33px” alt=”” align=”right”> </a> <?php } // And so on….. … Read more

Selecting a dynamic sidebar via metabox in wordpress

Your code seems a little superfluous; I’m pretty sure you could compact it to simply: <?php do_action( ‘before_sidebar’ ); if ( ! $sidebar = get_post_meta( get_the_ID(), ‘_cmb_test_select’, true ) ) $sidebar=”sidebar-1″; // Default sidebar if meta value does not exist. if ( ! dynamic_sidebar( $sidebar ) ) : ?> <!– No widgets for selected sidebar, … Read more

Display multiple “save draft button” on a post edit

One really simple way is to just insert another “save draft” button wherever you want in your post editor page. <input type=”submit” name=”save” value=”Save Draft” class=”button”> You essentially just want to make sure it’s got “save” as it’s name attribute and “Save Draft” as it’s value.

Set post title to same value as a tow meta box

Why do you need to remove the title? Generally it’s a bad idea, as the title generates the permalink, can’t think of any scenario where it would be necessary. Anyways, here is some code that looks like it does what you need: function add_custom_title( $data, $postarr ) { if($data[‘post_type’] == ‘myposttype’) { if(empty($data[‘post_title’]) { // … Read more