SlideShare uma empresa Scribd logo
1 de 45
Baixar para ler offline
COMBINING CUSTOM
POST TYPES, FIELDS,
AND META BOXES TO
DO THE IMPOSSIBLE
WITH WORDPRESS
 
 
function create_custom_post_type() {
register_post_type( 'sem_event', everything else );
}
array(
'labels' => array( 'name' => __( 'Events', 'SEM' ), ...),
'rewrite' => array( 'slug' => 'event'),
'has_archive' => 'events',
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-
fields')
)
add_action( 'init', 'create_custom_post_type' );
function create_custom_taxonomy() {
register_taxonomy( 'special-event-category', everything
else)
}
'hierarchical' => true
'hierarchical' => false
add_action( 'init', 'create_custom_taxonomy' );
add_action( 'init', 'create_custom_post_type' );
register_post_type(
'taxonomies' => array('special-event-category', 'special-
event-tag')
)
function create_custom_meta_box() {
add_meta_box('special_event_meta', 'Event Date &
Time', 'render_special_event_meta_box', 'sem_event',
'side', 'high');
}
function render_special_event_meta_box() {
require_once plugin_dir_path( __FILE__ ) .
'partials/special-event-manager-admin-display.php';
}
<li>
<label>Start Date</label>
<input name="sem_events_startdate" id="startPicker" value="<?php echo
</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
wp_create_nonce
echo '<input type="hidden" name="SEM-events-nonce" id="SEM-events-nonce"
wp_create_nonce( 'SEM-events-nonce' ) . '">';
$custom = get_post_custom($post->ID);
isset($custom["sem_events_startdate"][0]) ?
MON, JUN 29TH, 2015
date("D, M d, Y", the date);
2:31 PM
get_option('time_format');
date($time_format, the date);
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;
}
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 );
}
add_action( 'add_meta_boxes', 'create_custom_meta_box'
);
add_action( 'save_post', 'custom_meta_box_save' );
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 );
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' );
single-sem_event.php
single.php
index.php
$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);
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 }
$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>
$today6am = strtotime('today 6:00') + ( get_option(
'gmt_offset' ) * 3600 );
if ( $post_event_time > $today6am ) {
if( function_exists( 'ninja_forms_display_form' ) ){
ninja_forms_display_form( 6 ); }
}
archive-sem_event.php
archive.php
index.php
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'sem_events_startdate');
$query->set('order', 'ASC');
#WCMTL / @allilevine
git.io/semplugin

Mais conteúdo relacionado

Mais procurados

Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
camp_drupal_ua
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
Django Class-based views (Slovenian)
Django Class-based views (Slovenian)Django Class-based views (Slovenian)
Django Class-based views (Slovenian)
Luka Zakrajšek
 

Mais procurados (20)

jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Sins Against Drupal 2
Sins Against Drupal 2Sins Against Drupal 2
Sins Against Drupal 2
 
Symfony CoP: Form component
Symfony CoP: Form componentSymfony CoP: Form component
Symfony CoP: Form component
 
#wpbar 26/3 - Förenkla WP-admin
#wpbar 26/3 - Förenkla WP-admin#wpbar 26/3 - Förenkla WP-admin
#wpbar 26/3 - Förenkla WP-admin
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
Building secured wordpress themes and plugins
Building secured wordpress themes and pluginsBuilding secured wordpress themes and plugins
Building secured wordpress themes and plugins
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascript
 
20. CodeIgniter edit images
20. CodeIgniter edit images20. CodeIgniter edit images
20. CodeIgniter edit images
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
Django Class-based views (Slovenian)
Django Class-based views (Slovenian)Django Class-based views (Slovenian)
Django Class-based views (Slovenian)
 
Pengenalan blaast platform sdk
Pengenalan blaast platform sdkPengenalan blaast platform sdk
Pengenalan blaast platform sdk
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource ServicesAngularJS - $http & $resource Services
AngularJS - $http & $resource Services
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Codigo taller-plugins
Codigo taller-pluginsCodigo taller-plugins
Codigo taller-plugins
 
Command-Oriented Architecture
Command-Oriented ArchitectureCommand-Oriented Architecture
Command-Oriented Architecture
 

Semelhante a WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress

Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
Fabien Potencier
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
Jarod Ferguson
 
Building a Portfolio With Custom Post Types
Building a Portfolio With Custom Post TypesBuilding a Portfolio With Custom Post Types
Building a Portfolio With Custom Post Types
Alex Blackie
 

Semelhante a WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress (20)

Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helper
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
The Settings API
The Settings APIThe Settings API
The Settings API
 
WordPress as an application framework
WordPress as an application frameworkWordPress as an application framework
WordPress as an application framework
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Working with WooCommerce Custom Fields
Working with WooCommerce Custom FieldsWorking with WooCommerce Custom Fields
Working with WooCommerce Custom Fields
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Coding for Scale and Sanity
Coding for Scale and SanityCoding for Scale and Sanity
Coding for Scale and Sanity
 
Building a Portfolio With Custom Post Types
Building a Portfolio With Custom Post TypesBuilding a Portfolio With Custom Post Types
Building a Portfolio With Custom Post Types
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes to do the Impossible with WordPress