public
Last active

  • Download Gist
functions.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
<?php
 
// create post type
add_action( 'init', 'create_post_type' );
function create_post_type() {
 
$conf = array(
'public' => true,
'has_archive' => true,
'menu_position' => 5,
'show_in_nav_menus' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'content', 'page-attributes'),
'taxonomies' => array('category', 'post_tag'),
 
);
 
$conf['labels'] = array(
'name' => __( 'Architecte Posts' ),
'singular_name' => __( 'Architecte' )
);
$conf['rewrite'] = array('slug' => 'architect');
 
register_post_type( 'architect_subpage',$conf);
 
 
$conf['labels'] = array(
'name' => __( 'Interior Posts' ),
'singular_name' => __( 'Interior' )
);
$conf['rewrite'] = array('slug' => 'interior');
register_post_type( 'interior_subpage',$conf);
}
 
// remove posts menu since it's not in use
function remove_menus () {
global $menu;
$restricted = array(__('Posts'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
add_action('admin_menu', 'remove_menus');
 
 
 
 
/* Define the custom box */
add_action( 'add_meta_boxes', 'wpse_61041_add_custom_box' );
 
/* Do something with the data entered */
add_action( 'save_post', 'wpse_61041_save_postdata' );
 
/* Adds a box to the main column on the Post and Page edit screens */
function wpse_61041_add_custom_box() {
add_meta_box(
'wpse_61041_sectionid',
'Publish in Menu',
'wpse_61041_inner_custom_box',
'architect_subpage',
'side',
'high'
);
}
 
/* Prints the box content */
function wpse_61041_inner_custom_box($post)
{
// Use nonce for verification
wp_nonce_field( 'wpse_61041_wpse_61041_field_nonce', 'wpse_61041_noncename' );
 
// Get saved value, if none exists, "default" is selected
$saved = get_post_meta( $post->ID, 'in_menu', true);
if( !$saved )
$saved = 'no';
 
$fields = array(
'yes' => __('Yes', 'wpse'),
'no' => __('No', 'wpse'),
);
 
foreach($fields as $key => $label)
{
printf(
'<input type="radio" name="in_menu" value="%1$s" id="in_menu[%1$s]" %3$s />'.
'<label for="in_menu[%1$s]"> %2$s ' .
'</label><br>',
esc_attr($key),
esc_html($label),
checked($saved, $key, false)
);
}
}
 
/* When the post is saved, saves our custom data */
function wpse_61041_save_postdata( $post_id )
{
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
 
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['wpse_61041_noncename'], 'wpse_61041_wpse_61041_field_nonce' ) )
return;
 
if ( isset($_POST['in_menu']) && $_POST['in_menu'] != "" ){
 
update_post_meta( $post_id, 'in_menu', $_POST['in_menu'] );
 
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.