Our team – custom post type

/***** Adding custom post type - Our Team *****/

function ourteam_custom_init() {
	$labels = array(
		'name' => __('Our Teams','legal'),
		'singular_name' => __('ourteam','legal'),
		'add_new' => __('Add New','legal'),
		'add_new_item' => __('Add New Our Team','legal'),
		'edit_item' => __('Edit Our Team','legal'),
		'new_item' => __('New Our Team','legal'),
		'all_items' => __('All Our Teams','legal'),
		'view_item' => __('View Our Teams','legal'),
		'search_items' => __('Search Our Team','legal'),
		'not_found' => __('No Our Teams found','legal'),
		'not_found_in_trash' => __('No Our Teams found in Trash','legal'),
		'parent_item_colon' => '',
		'menu_name' => __('Our Teams','legal')
	);
	$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true,
		'show_in_menu' => true,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'ourteam' ),
		'capability_type' => 'post',
		'has_archive' => true,
		'hierarchical' => false,
		'menu_position' => null,
		'supports' => array( 'title', 'editor' , 'thumbnail')
	);

register_post_type( 'ourteam', $args );
}
add_action( 'init', 'ourteam_custom_init' );
/***** Testimonial Title Change *****/

/*****  Custom Meta Box - our Team *****/
/*1*/
add_action( 'add_meta_boxes', 'meta_box_ourteam_details' );
function meta_box_ourteam_details()
{
add_meta_box( 'meta_box_details', 'Details', 'ourteam_details', 'ourteam', 'normal', 'high' );
	add_meta_box( 'meta_box_details_title', 'Open Hours', 'ourteam_hours', 'ourteam', 'normal', 'high' );
}
function ourteam_details( $post )
{
	$values = get_post_custom( $post->ID );
	$title_speciality = isset( $values['title_speciality'] ) ? esc_attr( $values['title_speciality'][0] ) : '';
	$speciality = isset( $values['speciality'] ) ? esc_attr( $values['speciality'][0] ) : '';
	
	$title_degrees = isset( $values['title_degrees'] ) ? esc_attr( $values['title_degrees'][0] ) : '';
	$degrees = isset( $values['degrees'] ) ? esc_attr( $values['degrees'][0] ) : '';
	
	$title_address = isset( $values['title_address'] ) ? esc_attr( $values['title_address'][0] ) : '';
	$address = isset( $values['address'] ) ? esc_attr( $values['address'][0] ) : '';
	
	wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
	?>
		<p>
		<?php _e('Change Title [ Speciality ]','legal'); ?>
		<input type="text" name="title_speciality" value="<?php echo esc_attr( $title_speciality ); ?>" class="widefat" placeholder="<?php _e('Speciality','legal'); ?>" />
		<?php _e('Speciality :- ','legal'); ?>
		<input type="text" name="speciality" value="<?php echo esc_attr( $speciality ); ?>" class="widefat" placeholder="<?php _e('Speciality','legal'); ?>" />
		</p><br>
		<p>
		<?php _e('Change Title [ Degrees ]','legal'); ?>
		<input type="text" name="title_degrees" value="<?php echo esc_attr( $title_degrees ); ?>" class="widefat" placeholder="<?php _e('Degrees','legal'); ?>" />
		<?php _e('Degrees :- ','legal'); ?>
		<input type="text" name="degrees" value="<?php echo esc_attr( $degrees ); ?>" class="widefat" placeholder="<?php _e('Degrees','legal'); ?>" />
		</p><br>
		<p>
		<?php _e('Change Title [ Address ]','legal'); ?>
		<input type="text" name="title_address" value="<?php echo esc_attr( $title_address ); ?>" class="widefat" placeholder="<?php _e('Address','legal'); ?>" />
		<?php _e('Address :- ','legal'); ?>
		<input type="text" name="address" value="<?php echo esc_attr( $address ); ?>" class="widefat" placeholder="<?php _e('Address','legal'); ?>" />
		</p><br>
	<?php
}
function ourteam_hours( $post )
{
	$values = get_post_custom( $post->ID );
	$hours_monday_friday = isset( $values['hours_monday_friday'] ) ? esc_attr( $values['hours_monday_friday'][0] ) : '';
	$title_monday_friday = isset( $values['title_monday_friday'] ) ? esc_attr( $values['title_monday_friday'][0] ) : '';
	$title_saturday = isset( $values['title_saturday'] ) ? esc_attr( $values['title_saturday'][0] ) : '';
	$hours_saturday = isset( $values['hours_saturday'] ) ? esc_attr( $values['hours_saturday'][0] ) : '';
	$title_sunday = isset( $values['title_sunday'] ) ? esc_attr( $values['title_sunday'][0] ) : '';
	$hours_sunday = isset( $values['hours_sunday'] ) ? esc_attr( $values['hours_sunday'][0] ) : '';
	wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
	?>
		<p>
		<?php _e('Change Title [ Monday-Friday ]','legal'); ?>
		<input type="time" name="title_monday_friday" value="<?php echo esc_attr( $title_monday_friday ); ?>" class="widefat" placeholder="<?php _e('Change Title','legal'); ?>" />	
		<?php _e('Monday-Friday Time:- ','legal'); ?>
		<input type="time" name="hours_monday_friday" value="<?php echo esc_attr( $hours_monday_friday ); ?>" class="widefat" placeholder="<?php _e('Monday-Friday Time','legal'); ?>" />
		</p>
		<br>
		<p>
		<?php _e('Change Title [ Saturday ]	','legal'); ?>
		<input type="time" name="title_saturday" value="<?php echo esc_attr( $title_saturday ); ?>" class="widefat" placeholder="<?php _e('Change Title','legal'); ?>" />
		<?php _e('Saturday Time:- ','legal'); ?>
		<input type="time" name="hours_saturday" value="<?php echo esc_attr( $hours_saturday ); ?>" class="widefat" placeholder="<?php _e('Saturday Time','legal'); ?>" />
		</p>
		<br>
		<p>
		<?php _e('Change Title [ Sunday ]','legal'); ?>
		<input type="time" name="title_sunday" value="<?php echo esc_attr( $title_sunday ); ?>" class="widefat" placeholder="<?php _e('Change Title','legal'); ?>" />
		<?php _e('Sunday Time:- ','legal'); ?>
		<input type="time" name="hours_sunday" value="<?php echo esc_attr( $hours_sunday ); ?>" class="widefat" placeholder="<?php _e('Sunday Time','legal'); ?>" />
		</p><br>
	<?php
}
add_action( 'save_post', 'ourteam_meta_box_save' );
function ourteam_meta_box_save( $post_id )
{
	if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
	if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
	
	if( isset( $_POST['title_speciality'] ) ) update_post_meta( $post_id, 'title_speciality', esc_attr( $_POST['title_speciality'] ) );
	if( isset( $_POST['speciality'] ) ) update_post_meta( $post_id, 'speciality', esc_attr( $_POST['speciality'] ) );
	
	if( isset( $_POST['title_degrees'] ) ) update_post_meta( $post_id, 'title_degrees', esc_attr( $_POST['title_degrees'] ) );
	if( isset( $_POST['degrees'] ) ) update_post_meta( $post_id, 'degrees', esc_attr( $_POST['degrees'] ) );
	
	if( isset( $_POST['title_address'] ) ) update_post_meta( $post_id, 'title_address', esc_attr( $_POST['title_address'] ) );
	if( isset( $_POST['address'] ) ) update_post_meta( $post_id, 'address', esc_attr( $_POST['address'] ) );
	
	if( isset( $_POST['title_monday_friday'] ) ) update_post_meta( $post_id, 'title_monday_friday', esc_attr( $_POST['title_monday_friday'] ) );
	if( isset( $_POST['hours_monday_friday'] ) ) update_post_meta( $post_id, 'hours_monday_friday', esc_attr( $_POST['hours_monday_friday'] ) );
	
	if( isset( $_POST['title_saturday'] ) ) update_post_meta( $post_id, 'title_saturday', esc_attr( $_POST['title_saturday'] ) );
	if( isset( $_POST['hours_saturday'] ) ) update_post_meta( $post_id, 'hours_saturday', esc_attr( $_POST['hours_saturday'] ) );
	
	if( isset( $_POST['title_sunday'] ) ) update_post_meta( $post_id, 'title_sunday', esc_attr( $_POST['title_sunday'] ) );
	if( isset( $_POST['hours_sunday'] ) ) update_post_meta( $post_id, 'hours_sunday', esc_attr( $_POST['hours_sunday'] ) );
}

Display

<div class="row">
                <?php
                $legal_ourteam_args = array(
                    'paged' => $paged,
                    'orderby' => 'post_date',
                    'order' => 'ASC',
                    'post_type' => 'ourteam',
                    'post_status' => 'publish'
                );
                $legal_ourteam = new WP_Query($legal_ourteam_args);
                while ($legal_ourteam->have_posts()) {
                    $legal_ourteam->the_post();
                    ?> 
                    <div class="col-md-6 col-sm-6 attorneys">
                        <div class="our-section-box">
                            <?php if (has_post_thumbnail()) { ?>
                                <div class="col-md-6 no-padding our-box-left">
                                    <div class="img-hover">
                                        <?php the_post_thumbnail('legal-ourteam-thumbnail-image', array('alt' => get_the_title(), 'class' => 'img-responsive')); ?>
                                    </div>
                                </div>
                            <?php } ?>
                            <div class="col-md-6 our-box-right">
                                <a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4></a>
                                <span><?php echo get_post_meta(get_the_ID(), 'speciality', true); ?></span>
                                <?php the_excerpt(); ?>

                            </div>
                        </div>
                    </div>
                <?php } ?>		
            </div>
Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: