Change template on the fly based on post parent selection

This is how you do it… function update_post_template($post_id, $post){ //set $post_parent_id however you wish if ($post->post_parent == $post_parent_id) { //unhook save_post action to avoid infinite loop remove_action(‘save_post’, ‘update_post_template’); //change template update_post_meta( $post_id, ‘_wp_page_template’, ‘custom_template.php’ ); //re-hook save_post action add_action(‘save_post’, ‘update_post_template’); } } add_action(‘save_post’, ‘update_post_template’, 10, 2); Notes: To explain what is happening, first we hook … Read more

Auto Populate Custom Field with Complex Value That Increase by One?

I suppose you need somewhere to globally store last order number. Preferable in table wp_options. Method update_option will help you. Then you need to make a function which will fires everytime when new order appears. something like that: add_action( ‘save_post’, ‘setOrderNumber’); function setOrderNumber($post_id) { $slug = ‘orders’; // slug of your post_type called “Orders” if … Read more

Help with WP gallery function, wrap gallery in div

I just added a div to your function see comment in code: <?php add_filter( ‘post_gallery’, ‘my_post_gallery’, 10, 2 ); function my_post_gallery( $output, $attr ) { global $post, $wp_locale; static $instance = 0; $instance ++; if ( isset( $attr[‘orderby’] ) ) { $attr[‘orderby’] = sanitize_sql_orderby( $attr[‘orderby’] ); if( !$attr[‘orderby’] ) { unset( $attr[‘orderby’] ); } } … Read more

Image media upload metabox

In your JS you have twice the call to $(‘#dd_image’)and in your HTML you have no input named dd_image, but dd_image_one and dd_image_two… And also in your HTML you have twice id=”upload_image_button”and it’s bad :-). This way when you click on the first or the second button you do the same exact call and modify … Read more

Get_template_part inside a folder

I assume you have a file in templates/masterhead-templatename.php, and it works, it is ok. Correct me if I am wrong, you want to locate this file like this masterhead-templatename.php, basically one folder up, but this wordpress function does not work like this. If the file exists in the root’s theme folder, it does not recognize … Read more