wordcamp montreal 2015: combining custom post types, fields, and meta boxes to do the impossible...
TRANSCRIPT
![Page 1: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/1.jpg)
COMBINING CUSTOMPOST TYPES, FIELDS,AND META BOXES TODO THE IMPOSSIBLEWITH WORDPRESS
![Page 2: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/2.jpg)
![Page 3: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/3.jpg)
![Page 4: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/4.jpg)
![Page 5: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/5.jpg)
![Page 6: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/6.jpg)
![Page 7: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/7.jpg)
![Page 8: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/8.jpg)
![Page 9: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/9.jpg)
![Page 10: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/10.jpg)
function create_custom_post_type() {
register_post_type( 'sem_event', everything else );
}
![Page 11: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/11.jpg)
array(
'labels' => array( 'name' => __( 'Events', 'SEM' ), ...),'rewrite' => array( 'slug' => 'event'),'has_archive' => 'events','supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields')
)
![Page 12: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/12.jpg)
add_action( 'init', 'create_custom_post_type' );
![Page 13: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/13.jpg)
function create_custom_taxonomy() {
register_taxonomy( 'special-event-category', everythingelse)
}
![Page 14: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/14.jpg)
'hierarchical' => true
'hierarchical' => false
![Page 15: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/15.jpg)
add_action( 'init', 'create_custom_taxonomy' );
add_action( 'init', 'create_custom_post_type' );
![Page 16: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/16.jpg)
register_post_type(
'taxonomies' => array('special-event-category', 'special-event-tag')
)
![Page 17: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/17.jpg)
![Page 18: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/18.jpg)
![Page 19: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/19.jpg)
![Page 20: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/20.jpg)
function create_custom_meta_box() {
add_meta_box('special_event_meta', 'Event Date &Time', 'render_special_event_meta_box', 'sem_event','side', 'high');
}
![Page 21: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/21.jpg)
function render_special_event_meta_box() {
require_once plugin_dir_path( __FILE__ ) .'partials/special-event-manager-admin-display.php';
}
![Page 22: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/22.jpg)
<li> <label>Start Date</label> <input name="sem_events_startdate" id="startPicker" value="<?php echo $clean_sd; ?>"</li><li> <label>Start Time</label> <input name="sem_events_starttime" value="<?php echo $clean_st; ?>"</li>
Start Date Sat, Jul 4th, 2015
Start Time 2:00 pm
![Page 23: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/23.jpg)
wp_create_nonceecho '<input type="hidden" name="SEM-events-nonce" id="SEM-events-nonce" wp_create_nonce( 'SEM-events-nonce' ) . '">';
![Page 24: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/24.jpg)
$custom = get_post_custom($post->ID);
isset($custom["sem_events_startdate"][0]) ?
![Page 25: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/25.jpg)
MON, JUN 29TH, 2015date("D, M d, Y", the date);
2:31 PMget_option('time_format');
date($time_format, the date);
![Page 26: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/26.jpg)
function custom_meta_box_save() {
if ( !wp_verify_nonce( $_POST['SEM-events-nonce'], 'SEM-events-nonce' )) { return $post->ID; }if ( !current_user_can( 'edit_post', $post->ID )) return$post->ID;
}
![Page 27: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/27.jpg)
function custom_meta_box_save() {
if(!isset($_POST["sem_events_startdate"])):return $post;endif;$updatestartdate = strtotime ($_POST["sem_events_startdate"] .$_POST["sem_events_starttime"] );update_post_meta($post->ID, "sem_events_startdate",$updatestartdate );
}
![Page 28: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/28.jpg)
add_action( 'add_meta_boxes', 'create_custom_meta_box');
add_action( 'save_post', 'custom_meta_box_save' );
![Page 29: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/29.jpg)
![Page 30: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/30.jpg)
wp_enqueue_script( 'moment', plugin_dir_url( __FILE__ ) .'js/moment.js', array( ), 1.0, false );
wp_enqueue_script( 'pikaday', plugin_dir_url( __FILE__ ) .'js/pikaday.js', array( 'moment' ), 1.0, false );
wp_enqueue_script( special-event-manager, plugin_dir_url(__FILE__ ) . 'js/special-event-manager-admin.js', array('pikaday' ), 1.0, false );
![Page 31: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/31.jpg)
wp_enqueue_style( special-events-manager, plugin_dir_url(__FILE__ ) . 'css/special-event-manager-admin.css', array(),1.0, 'all' );
wp_enqueue_style( 'pikadaycss', plugin_dir_url( __FILE__ ) .'css/pikaday.css', array(), 1.0, 'all' );
![Page 32: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/32.jpg)
![Page 33: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/33.jpg)
single-sem_event.php
single.php
index.php
![Page 34: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/34.jpg)
$custom_fields = get_post_custom($post_id);
the date = $custom_fields["sem_events_startdate"][0];
the formatted date = date("D, M d, Y", the date);
![Page 35: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/35.jpg)
if there's no end date or time, then { July 4th at 2pm} else if there is an end time, but start date = end date {
July 4th from 2pm - 3pm} else if start date != end date {
July 4th at 2pm to July 5th at 5pm }
![Page 36: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/36.jpg)
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array( 250,255 ), false, '');
<img src="<?php $src[0] ?>">
<div style="background:url('<?php $src[0] ?>')"></div>
![Page 37: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/37.jpg)
$today6am = strtotime('today 6:00') + ( get_option('gmt_offset' ) * 3600 );
![Page 38: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/38.jpg)
if ( $post_event_time > $today6am ) {
if( function_exists( 'ninja_forms_display_form' ) ){ninja_forms_display_form( 6 ); }
}
![Page 39: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/39.jpg)
![Page 40: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/40.jpg)
archive-sem_event.php
archive.php
index.php
![Page 41: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/41.jpg)
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'sem_events_startdate');
$query->set('order', 'ASC');
![Page 42: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/42.jpg)
![Page 43: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/43.jpg)
![Page 44: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/44.jpg)
![Page 45: WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress](https://reader034.vdocuments.site/reader034/viewer/2022042615/55cc9896bb61ebf83c8b487e/html5/thumbnails/45.jpg)
#WCMTL / @allilevine
git.io/semplugin