SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
WORDPRESS CUSTOM POSTS
USING POST META BOXES
CHICAGO NORTHSIDE WORDPRESS MEETUP,
2/4/14
This presentation at:
http://bigwdesign.com/presentations/wp-custpost-coded.pdf
WHAT IS A CUSTOM POST?
NOTHING BUT AN ENTRY IN THE WP_POSTS
TABLE WITH A SPECIAL POST_TYPE TO
DISTINGUISH IT FROM OTHER POST TYPES.
And in our case, some associated wp_postmeta entries.
WHY USE CUSTOM POSTS?
You need a post type other than post or page.
Structured way for editors/users to consistently enter data.
Format posts consistently using a custom template.
You'd like to classify and access posts using some custom taxonomy.
EXAMPLE: GRILLS, INC.
Wants to implement a special product catalog site.
4 products now; 400 in a few years.
Site admin could create HTML and copy it indefinitely.
Prone to error, requires good HTML skills, hard for users.
Need simple, easy-to-use, structured input method, and a common
look.
Decision: Custom Post and template.
CODING APPROACH
Use of meta boxes for custom data ... as opposed to custom fields.
(Ease of creation vs. performance?)
It all ends up in wp_postmeta anyhow
Use add_action hooks into Wordpress: Hook a function on to a
specific WP action.
Use add_filters: Hook a function to a specific filter (run
before/modify a WP action).
PRESENTATION CODING TASKS
New plugin directory in wp-content/plugins (e.g., custom_grills)
A grills.php plugin file - nothing but a collection of functions
Admin post metaboxes to enter and save structured data
A single post template to display posts, single-grills.php
A hook into categories
Multi post template for categories, category-grills.php
BASIC PLUGIN STRUCTURE
Plugin Header - looks like comments
An add_action hook to run custom post registration function
Function to run register_post_type
Various function parameters
<pp
?h
/
*
Pui Nm:G il
lgn ae rls
Dsrp in C et a dmiti cso gilp ss
ecito: rae n an an u tm rl ot.
Vrin 10
eso: .
Ato: TryB
uhr er .
*
/
adat o('nt,' raegil) / eeue cet _rl weee aypg i gnrtd
d_cin i i' cet_ rl'; / xcts raegil hnv r n ae s eea e
fnto cet _rl( {
ucin raegil )
rgs e_ottp( 'rls,/ tl W w h v ti nwp s tp
eitrps _ye gil ' / el P e ae hs e ot ye
/ ec-pr mtr hr
/ t
aaees ee
COMPLETE CUSTOM POST TYPE CREATION
<pp
?h
/
*
Pui Nm:Gil
lgn ae rls
Dsrpin Cet admi ti c so gilpss
eci to: rae n anan utm rl ot.
Vrin 10
eso : .
Ato:Try B
uhr er .
*
/
adat o('nt,' raegil)
d_cin i i' cet_ rl';
fnto cet _rl( {
ucin raegil )
rgse_o ttp( 'rl s,
ei trps_ye gil'
a ry
ra(
'aes =
lbl ' >
ary
ra (
'a e
nm'
= 'rl s, 'ottp gnr lnm'
> Gil' p s ye eea ae ,
'i glrnm'
snua_ ae
= 'rl s, 'ottp snu a nm '
> Gil' p s ye iglr ae,
'd _e'
adnw
= 'd Nw,
> Ad e'
'd _e_tm
adnwi e'
= 'd NwGi l,
> Ad e rl'
'd tie'
ei_tm
= 'dt Gil,
> Ei rl'
'e _tm
nwie'
= 'e Gil,
> Nw rl'
'l _tm'
alies
= 'l Gil'
> Al rls,
'i wie'
ve_tm
= 'iw Gil,
> Ve rl'
'e rhies
sac_t m'
= 'er hGil'
> Sac rl s,
'o _on'
ntfud
= 'og il f ud,
> N rls on'
'o _on_nta h = 'og il i teT ah,
ntfud i_rs' > N rls n h rs'
'a etie_oo ' = ',
prn_t mcln
> '
'a et
prn'
= 'rl s
> Gil'
)
,
'hwi_a_ eu' = TU,
so_ nnvmns
> RE
'irrhcl = tu,
hea cia' > r e
'ecito' = ' od o rpout adpo utseii dt'
dsr pin
> H l s u r d c s n r d c p c f c a a,
'ulc
pbi '
= t u,
> re
'eupsto '= 5
mn_ oiin > ,
'uprs
spo t'
= a ry ' il' 'dtr ,' aeatiue ')
> ra( tte, ei o' pg-t rbts ,
'a_rhv' = t u
hsa cie
> re
)
)
;
}/ edfnt o
/ n ucin
?
>
DEMO 1. BASIC CUSTOM POST PLUGIN
Create the directory
Create grills.php
Add the basic grills.php code to wp-plugins
Add & activate plugin in WP back end
Create a custom post for grill #1, & test
Outcome: That's somewhat underwhelming.
ADD META BOXES TO BACK END
1. Admin_init function to add meta boxes to admin
2. Add function & HTML to display meta boxes
3. Add action to save contents of meta boxes
ADDING META BOXES
1. ADMIN_INIT FUNCTION TO ADD META BOXES
/ ato wl fr o ii o amn
/ ci n il ie n nt f di
adat o('di_n t,'yamn )
d_cin a mnii' m _di' ;
fnto m_d i( {
ucin yamn)
ad mt_o('r l_eabx,
d_eab x gilmt _o'
'rl Dtis,
Gil eal '
'ipa_ut mmt_o'
dsl ycso_ea bx,
'rls,'o ml,'ih
gil ' nra' hg'
)
;
}
ADDING META BOXES
2. ADD FUNCTION AND HTML TO DISPLAY
META BOXES
/ fnto wl dslymt -oe o b c ed
/ uc in i l ip a eabxs n ak n
fnto dsl ycso_ea bx $ rl ){
ucin ipa_ut mmt_o( gil
/ Rtiv vro sfed bsdo I
/ eree aiu il s ae n D
$u tmsre =echm (gtps_ ea $ rl-I,'e isnm' tu ))
cso_e is
s _ t l e _ o t m t ( g i l > D s r e _ a e, r e
;
$u tmmdl=e chm(gtp s_ea $rl-I ,'oe_ae ,tu ))
cso_o e
s_tl e_otm t( g il>D md lnm' re
;
/e c
/t
<a l>
tbe
<r
t>
< dsye "it:10" Sre <t>
t tl=wdh 0% >ei s / d
< d<nu tp = tx"sz = 8"nm =sr e_ae vle "?h eh $utm sre;?"
t>ipt ye"et ie"0 a e"eisnm " au = <pp co cso_eis >
<t>
/r
<r
t>
< dsye "it:10" Mdl/d
t tl=wdh 0% >oe < t >
< d<nu tp = tx"sz = 8"nm =md lnm" vle "?h eh $ utmmdl ?"
t > ipt ye"et ie"0 a e"oe_ae au=<pp co cso_ oe; >
<t>
/r
COMPLETE ADMIN METABOX FUNCTION
/ fnto wl dslymt -oe o b c ed
/ uc in i l ip a eabxs n ak n
fnto dsl ycso_ea bx $ rl ){
ucin ipa_ut mmt_o( gil
/ Rtiv vro sfld bsdo I
/ eree aiu ie s ae n D
$u tmsre =echm (gtps_ ea $ rl-I,'e isnm' tu ))
cso_e is
s _ t l e _ o t m t ( g i l > D s r e _ a e, r e
;
$u tmmdl=e chm(gtp s_ea $rl-I ,'oe_ae ,tu ))
cso_o e
s_tl e_otm t( g il>D md lnm' re
;
$i lgahc=e chm(gtp s_ea $rl-I ,'ilgah c,tu ))
tterp i
s_tl e_otm t( g il>D tt erpi' r e
;
$u tmiae=e chm(gtp s_ea $rl-I ,'utmia e,tu ))
cso_m g
s_tl e_otm t( g il>D cs o_mg' r e
;
$m g_ato =echm (gtps_ ea $ rl-I,'m g_ato' tu ))
iaecp in
s_tl e_ otmt( gil> D iaecp in, re
;
$o kn_ufc =ech m(gtps _ea $rl-I,' okn_ufc ' tu ))
coigs rae
s_tl e _otmt( gil >D coig srae, re
;
$t _rmr =echm( gtps_e a $r l-I,'t_ rmr' tu ))
bupia y
s _tl e_o tmt( gil>D bupiay, re
;
$t _eodr =echm (gtps_ ea $ rl-I,'t _eodr' tu ))
buscn ay
s_tl e_ otmt( gil> D buscn ay, re
;
$u _u = echm(gt ps_ea $rl- I,'u_u' tu ))
ctot
s_t l e_otm t( gil>D c tot, re
;
$i eunr=ec hm(gtps _ea $rl-I,'ieunr ,tu ) )
sdbre
s_tl e_otmt ( gi l>D sdb re' re
;
$x ep = echm(gt ps_ea $rl- I,'xep' tu ))
ecrt
s_t l e_otm t( gil>D e crt, re
;
?
>
<a l>
tbe
<r
t>
< dsye "it:10" Sre <t>
t tl=wdh 0% >ei s / d
< d<nu tp = tx"sz = 8"nm =sr e_ae vle "?h eh $utm sre;?"
t>ipt ye"et ie"0 a e"eisnm " au = <pp co cso_eis >
<t>
/r
<r
t>
< dsye "it:10" Mdl/d
t tl=wdh 0% >oe < t >
< d<nu tp = tx"sz = 8"nm =md lnm" vle "?h eh $ utmmdl ?"
t > ipt ye"et ie"0 a e"oe_ae au=<pp co cso_ oe; >
<t>
/r
<r
t>
< dsye "it:10" TteGah c /d
t tl=wdh 0% >il rpi < t >
< d<n u t p = t x " s z = 8 "n m =t t e r p i " v l e" ? h e h $ i l g a h c ? "
t > ipt ye"et ie"0 a e"ilgah c au=<p p co tte rpi; >
<t>
/r
<r
t>
ADDING META BOXES
3. ADD ACTION TO SAVE META
BOXES/FIELDS
/ fnto wl ad dt t w_otea o sv _ot I ps _ye=gil
/ uc in i l d aa o pps mt n aeps, F ottp
rls
adat o('aeps ' 'd _rl_il s,1,2) / pirt &ag
d_cin s v_ot, adgil fed' 0
; / ro iy
rs
fnto adg ilfed($ rl_d $rl ){
ucin d_rl_i ls gili , g il
/ Cekp s tp frg il
/ hc ot ye o rls
i ($rl -ps_ye= 'rl s ) {
f
gil>ot tp = gil'
/ Soed t i ps mt tbei peeti ps dt
/ tr aa n ot e a al f rsn n ot aa
i ( i s t $ P S [ s r e _ a e] ) & $ P S [ s r e _ a e ] ! ' ) {
f
se( _OT ' eisnm'
& _OT'eis nm' = '
udt_o tmt($rl _d 'eisnm' $PS [sre_ae])
p aeps_ea gili, sre _ae, _OT'ei snm' ;
}
/ ec
/ t
COMPLETE META BOX/FIELD SAVE
FUNCTION
/ adsv_o tato t a dgilfe d it ps_ ea
/ d aeps ci n o d rl ils no otmt
a d a t o ( ' a e p s ' ' d _ r l _ i l s, 1 , 2)
d_cin s v_ot, adgil fed' 0
;
fnto adg ilfed($ rl_d $rl ){
ucin d_rl_i ls gili, g il
/ Cekp s tp frg il
/ hc ot ye o rls
i ($rl -ps_ye= 'rl s ) {
f
g i l> o t t p = g i l '
/ So edt i ps mt tbe i pe eti ps d t
/ tr aa n ot ea al f rsn n ot aa
i ( i s t $ P S[ s r e _ a e] ) & $ P S [ s r e _ a e ] ! ' ) {
f
se( _OT' eisnm'
& _OT'eis nm' = '
udt_o tmt($rl _d 'eisnm' $PS[sre_ae])
p aeps_ea gili, sre _ae, _OT'ei snm' ;
}
i ( i s t $ P S[ m d l n m ' ) & $ P S[ m d l n m ' ! ' ) {
f
se( _OT' oe_ae]
& _OT' oe_ae] = '
udt_o tmt( $rl _d 'oe_ae , $PS [mdl nm' )
p aeps_ea gili, mdl nm' _OT 'oe_ae ] ;
}
i ( i s t $ P S[ t t e r p i ' ) & $ P S [t t e r p i ' ! ' ) {
f
se( _OT' ilgahc]
& _OT 'ilgahc ] = '
udt_o tmt( $rl _d 'ilgahc , $PS [tt erpi' )
p aeps_ea gili, tte rpi' _O T'ilgah c] ;
}
i ( i s t $ P S[ c s o _ m g ' ) & $ P S [c s o _ m g ' ! ' ) {
f
se( _OT' utmiae]
& _OT 'utmiae ] = '
udt_o tmt( $rl _d 'utmiae , $PS [cs o_mg' )
p aeps_ea gili, cso _mg' _O T'utmia e] ;
}
i ( i s t $ P S[ i a e c p i n] ) & $ P S [ i a e c p i n] ! ' ) {
f
se( _OT' mg_ato '
& _OT'mg _ato' = '
u d t _ o t m t ( $ r l _ d ' m g _ a t o ' $ P S[ i a e c p i n] )
p aeps_ea gili, iae cpin , _OT'm g_ato' ;
}
i ( i s t $ P S[ c o i g s r a e] ) & $ P S[ c o i g s r a e] ! ' ) {
f
se( _OT' okn_uf c'
& _OT'o kn_ufc' = '
u d t _ o t m t ( $ r l _ d ' o k n _ u f c ' $ P S[ c o i g s r a e] )
p aeps_ea gili, coi gsrae , _OT' okn_ufc ' ;
}
i ( i s t $ P S[ b u p i a y] ) & $ P S [ b u p i a y ] ! ' ) {
f
se( _OT' t_rmr'
& _OT't_r mr' = '
udt_o tmt($rl _d 't_rmr' $PS[bupiay])
p aeps_ea gili, bup iay, _OT't_ rmr' ;
}
i ( i s t $ P S[ b u s c n a y] ) & $ P S [ b u s c n a y] ! ' ) {
f
se( _OT' t_eodr '
& _OT't_ eodr' = '
u d t _ o t m t ( $ r l _ d ' t _ e o d r ' $ P S[ b u s c n a y] )
p aeps_ea gili, bus cnay , _OT't _eodr' ;
}
i ( i s t $ P S[ c t o t ] ) & $ P S [c t o t ] ! ' ) {
f
se( _OT' u_u'
& _O T'u_u' = '
udt_o tmt( $rl _d 'u_u' $PS [c tot ])
p aeps_ea gili, cto t, _ OT'u_u' ;
}
i ( i s t $ P S[ s d b r e ' ) & $ P S[ s d b r e ' ! ' ) {
f
se( _OT' ieunr]
& _OT' ieunr] = '
udt_o tmt( $rl _d 'ieunr , $PS [sdb re' )
p aeps_ea gili, sdb re' _OT 'ieunr ] ;
}
i ( i s t $ P S[ e c r t ] ) & $ P S [e c r t ] ! ' ) {
f
se( _OT' xep'
& _O T'xep' = '
udt_o tmt( $rl _d 'xep' $PS [e crt ])
p aeps_ea gili, ecr t, _ OT'xep' ;
}
}
}
DEMO 2. METABOXES
Add the three Meta Box functions to grills.php
Add some data to grill #1
Create grill #2 and add data to it as well
Outcome: Metaboxes added to back end, and we are saving custom
post data
CUSTOM SINGLE TEMPLATE
1. Add action to register special style sheet
2. Add filter to use special template
3. Create single item template
CREATING CUSTOM SINGLE TEMPLATE
1. ADD ACTION TO REGISTER SPECIAL STYLE
SHEET
/ rgse tecsw aeg igt uewt orcso tml t
/ ei tr h s e r on o s ih u utm epae
adat o('peqe esrps,' eitrgi lsye')
d_cin w _nuu_ci t' rgs e_rl_tl s ;
fnto rgs e_rl_tl s){
ucin eitrgi lsye(
w_ eitrsye 'ut mgil' puis ul ' cso_rls csgilsy ecs ))
prgse _tl( cso_rl s, lgn_r ( /utm gil/s/r l-tl.s'
;
w_ nuu_tl( 'utmgil ')
peqee sye cso _rls ;
}
CREATING CUSTOM SINGLE TEMPLATE
2. ADD FILTER TO USE SPECIAL TEMPLATE
/ freueo ddc tdtmlt
/ oc s f eiae e pae
adfl e('iget mlt' 'e_ut mps_yet mlt')
d_itr s nl_epae , gt cso_ot tp_epae ;
fnto gtc so_ottp _epae$ igetmlt){
ucin e_utmp s_yetml t( snl_ epae
goa $ot
l bl p s;
i (ps-ps_ ye= 'rls ){
f $ot >ottp = gil '
$ i g e t m l t = d r a e _ F L _ ) . ' s n l - r l s p p;
sn l_epae
inm ( _ IE_
/igeg il.h'
}
/ eh " snl_epa e;
/ co $ige tmlt"
/ de)
/ i(;
rtr $iget mlt;
e un s nl_epae
}
CREATING CUSTOM SINGLE TEMPLATE
3. CREATE SINGLE ITEM TEMPLATE - COPY &
MODIFY THEME'S SINGLE.PHP
(JUST LIKE BUILDING A STANDARD WORDPRESS
TEMPLATE, BUT WITH YOUR CUSTOM LAYOUT AND
DATA)
<pp
?h
gtha e(;?
e_edr) >
<i i =pia y >
dv d "rmr"
<i i =c net rl = mi"
d v d" o t n " o e " a n>
<p p
?h
/ $yot =ary 'ottp' = ' utmpout ' )
/ mps
ra ( ps _ye > cso_ rdcs, ;
/ $op= nwW_ur( $yot)
/ lo
e P Qey mps ;
?
>
<p p/ w ie($op> aepss) ):$op>h _ot)
?h / hl
lo-hv_o t(
l o-teps( ;
wie (hv_ot( ):t eps(;?
hl
ae pss)
h_o t) >
/ ec
/ t
DEMO 3. CUSTOM TEMPLATE
Add the code to grills.php, create single-grills.php
Note that our custom post now shows in a custom template
MIGHT WANT TO VIEW MORE THAN ONE
PRODUCT FROM MENU SELECTION
Create a Custom taxonomy (another day)
Add custom post type to existing Category system
ADDING A CUSTOM POST TYPE TO EXISTING
CATEGORY SYSTEM
1. Modify register_post to include taxonomy Category
2. Add pre_get_posts action that will add our post type to main
query
3. Create category-grills.php template to display multiple posts
ADDING CUSTOM POST TYPE TO
CATEGORIES
1. MODIFY REGISTER_POST TO INCLUDE
TAXONOMY CATEGORY
ADD ONE LINE (TAXONOMIES) TO BOTTOM OF
FUNCTION CREATE_GRILL
/ ecec
/ t t
'eupsto '= 5
mn_ oiin > ,
'uprs
spo t'
= a r y ' i l' ' d t r , ' a ea t i u e ' )
> ra( tte , ei o' pg-t rbts ,
'a_rhv ' = t u,
hsa cie
> re
'aoois = ary'ae oy)
txn me' > ra (ctgr'
)
ADDING CUSTOM POST TYPE TO
CATEGORIES
2. ADD PRE_GET_POSTS ACTION THAT WILL
ADD POST TYPE TO MAIN QUERY
NEW FUNCTION ADDED TO GRILLS.PHP
/ So psso 'ot,'a e ad 'rls ps tpso hm pg
/ hw ot f ps ' pg' n gi l' o t ye n o e ae
adat o('r_e_ ot' 'd_rl_ ottp_oq ey )
d_cin p egtpss, adg ilps_y et_ur' ;
fnto adg ilps_ye t_ur($ ur ) {
ucin d_rl_o ttp_oqe y qey
i ($ur -i_anqe y ))
f
qey>sm i_ur (
$ur-st 'ott p' a ry 'ot,'ae ,'rls ))
qey >e( ps_ye, ra( ps' pg' gi l'
;
rt r $u r;
eun qey
}
ADDING CUSTOM POST TYPE TO
CATEGORIES
3. CREATE CATEGORY-GRILLS.PHP TEMPLATE
TO DISPLAY MULTIPLE POSTS
Copy category.php from main template to our plugin dir, and modify
as needed
Add new filter on archive_template to force use of our archive
template
Add some Wordpress categories in backend, assign posts, make menu
items!
/ freueo ddc tdctgr tml t
/ oc s f eiae a eoy epae
adfl e('aeoy tmlt' 'e_r lsctgr_ epae )
d_itr c tgr_epa e, g tgil_a eoytmlt ' ;
fnto gtg il_aeoy tmlt(c tgr_epa e {
ucin e_rlsc tgr_epa e$aeoy tmlt)
goa $ot
lb l ps;
i ( p s - p s _ y e = ' r l s ){
f $ot> ottp = gil'
$ a e o y t m l t = d r a e _ F L _ ). ' c t g r - r l s p p ;
ctg r_epae
inm ( _IE_
/ aeoy gil .h'
}
rtr $aeoyt mlt;
eu n ct gr_epae
}
DEMO 4. CUSTOM POSTS BY CATEGORY
Modify main function to add taxonomy
Add function to include grills in posts query
Add function to force use of category-grills template
Add some special grill categories to back end and assign
posts
Menu items to those categories
Outcome: Menu items display categories of custom posts
THE END
Presentation originally developed from tutorials at:
http://wp.tutsplus.com/tutorials/plugins/a-guide-towordpress-custom-post-types-creation-display-and-metaboxes/
http://wp.tutsplus.com/tutorials/plugins/a-guide-towordpress-custom-post-types-taxonomies-admin-columnsfilters-and-archives/
See also Wordpress codex on post_types (has many other links):
http://codex.wordpress.org/Post_Types
This presentation:
http://bigwdesign.com/presentations/wp-custpost-coded.pdf
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin
Create Custom Post Type Plugin

Más contenido relacionado

La actualidad más candente

irine grishikashvili0003 (1).PDF
irine grishikashvili0003 (1).PDFirine grishikashvili0003 (1).PDF
irine grishikashvili0003 (1).PDF
Irine Grishkashvili
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
Michael Peacock
 
R57shell
R57shellR57shell
R57shell
ady36
 

La actualidad más candente (20)

穏やかにファイルを削除する
穏やかにファイルを削除する穏やかにファイルを削除する
穏やかにファイルを削除する
 
Flow of events during Media Player creation in Android
Flow of events during Media Player creation in AndroidFlow of events during Media Player creation in Android
Flow of events during Media Player creation in Android
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
PHP Tutorial (funtion)
PHP Tutorial (funtion)PHP Tutorial (funtion)
PHP Tutorial (funtion)
 
irine grishikashvili0003 (1).PDF
irine grishikashvili0003 (1).PDFirine grishikashvili0003 (1).PDF
irine grishikashvili0003 (1).PDF
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and Beyond
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Inc
IncInc
Inc
 
Mkpd proposal dan disertasi Ilmu Administrasi Publik
Mkpd proposal dan disertasi Ilmu Administrasi PublikMkpd proposal dan disertasi Ilmu Administrasi Publik
Mkpd proposal dan disertasi Ilmu Administrasi Publik
 
R57shell
R57shellR57shell
R57shell
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
PHP 1
PHP 1PHP 1
PHP 1
 
8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会
 
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011
 
Nop2
Nop2Nop2
Nop2
 
R57.Php
R57.PhpR57.Php
R57.Php
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 

Destacado (6)

Web Fonts: Why Bother?
Web Fonts: Why Bother?Web Fonts: Why Bother?
Web Fonts: Why Bother?
 
MIWheat AR 2014
MIWheat AR 2014MIWheat AR 2014
MIWheat AR 2014
 
Textorize
TextorizeTextorize
Textorize
 
Bootstrap 3
Bootstrap 3Bootstrap 3
Bootstrap 3
 
Webfonts and Web Typography
Webfonts and Web TypographyWebfonts and Web Typography
Webfonts and Web Typography
 
Custom Post Type - Create and Display
Custom Post Type - Create and DisplayCustom Post Type - Create and Display
Custom Post Type - Create and Display
 

Similar a Create Custom Post Type Plugin

Itsecteam shell
Itsecteam shellItsecteam shell
Itsecteam shell
ady36
 
Toan pt.de075.2012
Toan pt.de075.2012Toan pt.de075.2012
Toan pt.de075.2012
BẢO Hí
 
2c a 6ox . l H. 9 n c t d o t {E€g f.docx
2c a 6ox  . l  H.  9 n c t d o t {E€g f.docx2c a 6ox  . l  H.  9 n c t d o t {E€g f.docx
2c a 6ox . l H. 9 n c t d o t {E€g f.docx
gilbertkpeters11344
 

Similar a Create Custom Post Type Plugin (20)

WordPress in 30 minutes
WordPress in 30 minutesWordPress in 30 minutes
WordPress in 30 minutes
 
Social Network Analysis With R
Social Network Analysis With RSocial Network Analysis With R
Social Network Analysis With R
 
Using Phing for Fun and Profit
Using Phing for Fun and ProfitUsing Phing for Fun and Profit
Using Phing for Fun and Profit
 
Evolving the Android Core with Aspects
Evolving the Android Core with AspectsEvolving the Android Core with Aspects
Evolving the Android Core with Aspects
 
Tercera parte parte del Cuaderno de Ingles
Tercera parte parte del Cuaderno de InglesTercera parte parte del Cuaderno de Ingles
Tercera parte parte del Cuaderno de Ingles
 
Feedback gulele &amp;shuro meda 2009
Feedback gulele &amp;shuro meda 2009Feedback gulele &amp;shuro meda 2009
Feedback gulele &amp;shuro meda 2009
 
A Backbone.js Tutorial for the Impatient - Part 1
A Backbone.js Tutorial for the Impatient - Part 1A Backbone.js Tutorial for the Impatient - Part 1
A Backbone.js Tutorial for the Impatient - Part 1
 
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
 
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
 
Build a custom (micro)framework with ZF2 Components (as building blocks)
Build a custom (micro)framework with ZF2 Components (as building blocks)Build a custom (micro)framework with ZF2 Components (as building blocks)
Build a custom (micro)framework with ZF2 Components (as building blocks)
 
Itsecteam shell
Itsecteam shellItsecteam shell
Itsecteam shell
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)
 
Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)
 
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
 
Toan pt.de075.2012
Toan pt.de075.2012Toan pt.de075.2012
Toan pt.de075.2012
 
Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)
 
Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
 
2c a 6ox . l H. 9 n c t d o t {E€g f.docx
2c a 6ox  . l  H.  9 n c t d o t {E€g f.docx2c a 6ox  . l  H.  9 n c t d o t {E€g f.docx
2c a 6ox . l H. 9 n c t d o t {E€g f.docx
 
32.28
32.2832.28
32.28
 

Más de Jan Wilson (9)

Canzonetta Black and White
Canzonetta Black and WhiteCanzonetta Black and White
Canzonetta Black and White
 
Cazonetta Contact Sheet Color
Cazonetta Contact Sheet ColorCazonetta Contact Sheet Color
Cazonetta Contact Sheet Color
 
Contact sheet-wallace-bowl-3
Contact sheet-wallace-bowl-3Contact sheet-wallace-bowl-3
Contact sheet-wallace-bowl-3
 
Contact sheet-wallace-bowl-2
Contact sheet-wallace-bowl-2Contact sheet-wallace-bowl-2
Contact sheet-wallace-bowl-2
 
Contactsheet Wallace Bowl 1
Contactsheet Wallace Bowl 1Contactsheet Wallace Bowl 1
Contactsheet Wallace Bowl 1
 
Contactsheet canz-bw
Contactsheet canz-bwContactsheet canz-bw
Contactsheet canz-bw
 
Colleen plumb
Colleen plumbColleen plumb
Colleen plumb
 
Canz contact-sheet-color
Canz contact-sheet-colorCanz contact-sheet-color
Canz contact-sheet-color
 
My favorite word press plugins 2016
My favorite word press plugins  2016My favorite word press plugins  2016
My favorite word press plugins 2016
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Create Custom Post Type Plugin

  • 1. WORDPRESS CUSTOM POSTS USING POST META BOXES CHICAGO NORTHSIDE WORDPRESS MEETUP, 2/4/14 This presentation at: http://bigwdesign.com/presentations/wp-custpost-coded.pdf
  • 2. WHAT IS A CUSTOM POST? NOTHING BUT AN ENTRY IN THE WP_POSTS TABLE WITH A SPECIAL POST_TYPE TO DISTINGUISH IT FROM OTHER POST TYPES. And in our case, some associated wp_postmeta entries.
  • 3. WHY USE CUSTOM POSTS? You need a post type other than post or page. Structured way for editors/users to consistently enter data. Format posts consistently using a custom template. You'd like to classify and access posts using some custom taxonomy.
  • 4. EXAMPLE: GRILLS, INC. Wants to implement a special product catalog site. 4 products now; 400 in a few years. Site admin could create HTML and copy it indefinitely. Prone to error, requires good HTML skills, hard for users. Need simple, easy-to-use, structured input method, and a common look. Decision: Custom Post and template.
  • 5. CODING APPROACH Use of meta boxes for custom data ... as opposed to custom fields. (Ease of creation vs. performance?) It all ends up in wp_postmeta anyhow Use add_action hooks into Wordpress: Hook a function on to a specific WP action. Use add_filters: Hook a function to a specific filter (run before/modify a WP action).
  • 6. PRESENTATION CODING TASKS New plugin directory in wp-content/plugins (e.g., custom_grills) A grills.php plugin file - nothing but a collection of functions Admin post metaboxes to enter and save structured data A single post template to display posts, single-grills.php A hook into categories Multi post template for categories, category-grills.php
  • 7. BASIC PLUGIN STRUCTURE Plugin Header - looks like comments An add_action hook to run custom post registration function Function to run register_post_type Various function parameters <pp ?h / * Pui Nm:G il lgn ae rls Dsrp in C et a dmiti cso gilp ss ecito: rae n an an u tm rl ot. Vrin 10 eso: . Ato: TryB uhr er . * / adat o('nt,' raegil) / eeue cet _rl weee aypg i gnrtd d_cin i i' cet_ rl'; / xcts raegil hnv r n ae s eea e fnto cet _rl( { ucin raegil ) rgs e_ottp( 'rls,/ tl W w h v ti nwp s tp eitrps _ye gil ' / el P e ae hs e ot ye / ec-pr mtr hr / t aaees ee
  • 8. COMPLETE CUSTOM POST TYPE CREATION <pp ?h / * Pui Nm:Gil lgn ae rls Dsrpin Cet admi ti c so gilpss eci to: rae n anan utm rl ot. Vrin 10 eso : . Ato:Try B uhr er . * / adat o('nt,' raegil) d_cin i i' cet_ rl'; fnto cet _rl( { ucin raegil ) rgse_o ttp( 'rl s, ei trps_ye gil' a ry ra( 'aes = lbl ' > ary ra ( 'a e nm' = 'rl s, 'ottp gnr lnm' > Gil' p s ye eea ae , 'i glrnm' snua_ ae = 'rl s, 'ottp snu a nm ' > Gil' p s ye iglr ae, 'd _e' adnw = 'd Nw, > Ad e' 'd _e_tm adnwi e' = 'd NwGi l, > Ad e rl' 'd tie' ei_tm = 'dt Gil, > Ei rl' 'e _tm nwie' = 'e Gil, > Nw rl' 'l _tm' alies = 'l Gil' > Al rls, 'i wie' ve_tm = 'iw Gil, > Ve rl' 'e rhies sac_t m' = 'er hGil' > Sac rl s, 'o _on' ntfud = 'og il f ud, > N rls on' 'o _on_nta h = 'og il i teT ah, ntfud i_rs' > N rls n h rs' 'a etie_oo ' = ', prn_t mcln > ' 'a et prn' = 'rl s > Gil' ) , 'hwi_a_ eu' = TU, so_ nnvmns > RE 'irrhcl = tu, hea cia' > r e 'ecito' = ' od o rpout adpo utseii dt' dsr pin > H l s u r d c s n r d c p c f c a a, 'ulc pbi ' = t u, > re 'eupsto '= 5 mn_ oiin > , 'uprs spo t' = a ry ' il' 'dtr ,' aeatiue ') > ra( tte, ei o' pg-t rbts , 'a_rhv' = t u hsa cie > re ) ) ; }/ edfnt o / n ucin ? >
  • 9. DEMO 1. BASIC CUSTOM POST PLUGIN Create the directory Create grills.php Add the basic grills.php code to wp-plugins Add & activate plugin in WP back end Create a custom post for grill #1, & test Outcome: That's somewhat underwhelming.
  • 10. ADD META BOXES TO BACK END 1. Admin_init function to add meta boxes to admin 2. Add function & HTML to display meta boxes 3. Add action to save contents of meta boxes
  • 11. ADDING META BOXES 1. ADMIN_INIT FUNCTION TO ADD META BOXES / ato wl fr o ii o amn / ci n il ie n nt f di adat o('di_n t,'yamn ) d_cin a mnii' m _di' ; fnto m_d i( { ucin yamn) ad mt_o('r l_eabx, d_eab x gilmt _o' 'rl Dtis, Gil eal ' 'ipa_ut mmt_o' dsl ycso_ea bx, 'rls,'o ml,'ih gil ' nra' hg' ) ; }
  • 12. ADDING META BOXES 2. ADD FUNCTION AND HTML TO DISPLAY META BOXES / fnto wl dslymt -oe o b c ed / uc in i l ip a eabxs n ak n fnto dsl ycso_ea bx $ rl ){ ucin ipa_ut mmt_o( gil / Rtiv vro sfed bsdo I / eree aiu il s ae n D $u tmsre =echm (gtps_ ea $ rl-I,'e isnm' tu )) cso_e is s _ t l e _ o t m t ( g i l > D s r e _ a e, r e ; $u tmmdl=e chm(gtp s_ea $rl-I ,'oe_ae ,tu )) cso_o e s_tl e_otm t( g il>D md lnm' re ; /e c /t <a l> tbe <r t> < dsye "it:10" Sre <t> t tl=wdh 0% >ei s / d < d<nu tp = tx"sz = 8"nm =sr e_ae vle "?h eh $utm sre;?" t>ipt ye"et ie"0 a e"eisnm " au = <pp co cso_eis > <t> /r <r t> < dsye "it:10" Mdl/d t tl=wdh 0% >oe < t > < d<nu tp = tx"sz = 8"nm =md lnm" vle "?h eh $ utmmdl ?" t > ipt ye"et ie"0 a e"oe_ae au=<pp co cso_ oe; > <t> /r
  • 13. COMPLETE ADMIN METABOX FUNCTION / fnto wl dslymt -oe o b c ed / uc in i l ip a eabxs n ak n fnto dsl ycso_ea bx $ rl ){ ucin ipa_ut mmt_o( gil / Rtiv vro sfld bsdo I / eree aiu ie s ae n D $u tmsre =echm (gtps_ ea $ rl-I,'e isnm' tu )) cso_e is s _ t l e _ o t m t ( g i l > D s r e _ a e, r e ; $u tmmdl=e chm(gtp s_ea $rl-I ,'oe_ae ,tu )) cso_o e s_tl e_otm t( g il>D md lnm' re ; $i lgahc=e chm(gtp s_ea $rl-I ,'ilgah c,tu )) tterp i s_tl e_otm t( g il>D tt erpi' r e ; $u tmiae=e chm(gtp s_ea $rl-I ,'utmia e,tu )) cso_m g s_tl e_otm t( g il>D cs o_mg' r e ; $m g_ato =echm (gtps_ ea $ rl-I,'m g_ato' tu )) iaecp in s_tl e_ otmt( gil> D iaecp in, re ; $o kn_ufc =ech m(gtps _ea $rl-I,' okn_ufc ' tu )) coigs rae s_tl e _otmt( gil >D coig srae, re ; $t _rmr =echm( gtps_e a $r l-I,'t_ rmr' tu )) bupia y s _tl e_o tmt( gil>D bupiay, re ; $t _eodr =echm (gtps_ ea $ rl-I,'t _eodr' tu )) buscn ay s_tl e_ otmt( gil> D buscn ay, re ; $u _u = echm(gt ps_ea $rl- I,'u_u' tu )) ctot s_t l e_otm t( gil>D c tot, re ; $i eunr=ec hm(gtps _ea $rl-I,'ieunr ,tu ) ) sdbre s_tl e_otmt ( gi l>D sdb re' re ; $x ep = echm(gt ps_ea $rl- I,'xep' tu )) ecrt s_t l e_otm t( gil>D e crt, re ; ? > <a l> tbe <r t> < dsye "it:10" Sre <t> t tl=wdh 0% >ei s / d < d<nu tp = tx"sz = 8"nm =sr e_ae vle "?h eh $utm sre;?" t>ipt ye"et ie"0 a e"eisnm " au = <pp co cso_eis > <t> /r <r t> < dsye "it:10" Mdl/d t tl=wdh 0% >oe < t > < d<nu tp = tx"sz = 8"nm =md lnm" vle "?h eh $ utmmdl ?" t > ipt ye"et ie"0 a e"oe_ae au=<pp co cso_ oe; > <t> /r <r t> < dsye "it:10" TteGah c /d t tl=wdh 0% >il rpi < t > < d<n u t p = t x " s z = 8 "n m =t t e r p i " v l e" ? h e h $ i l g a h c ? " t > ipt ye"et ie"0 a e"ilgah c au=<p p co tte rpi; > <t> /r <r t>
  • 14. ADDING META BOXES 3. ADD ACTION TO SAVE META BOXES/FIELDS / fnto wl ad dt t w_otea o sv _ot I ps _ye=gil / uc in i l d aa o pps mt n aeps, F ottp rls adat o('aeps ' 'd _rl_il s,1,2) / pirt &ag d_cin s v_ot, adgil fed' 0 ; / ro iy rs fnto adg ilfed($ rl_d $rl ){ ucin d_rl_i ls gili , g il / Cekp s tp frg il / hc ot ye o rls i ($rl -ps_ye= 'rl s ) { f gil>ot tp = gil' / Soed t i ps mt tbei peeti ps dt / tr aa n ot e a al f rsn n ot aa i ( i s t $ P S [ s r e _ a e] ) & $ P S [ s r e _ a e ] ! ' ) { f se( _OT ' eisnm' & _OT'eis nm' = ' udt_o tmt($rl _d 'eisnm' $PS [sre_ae]) p aeps_ea gili, sre _ae, _OT'ei snm' ; } / ec / t
  • 15. COMPLETE META BOX/FIELD SAVE FUNCTION / adsv_o tato t a dgilfe d it ps_ ea / d aeps ci n o d rl ils no otmt a d a t o ( ' a e p s ' ' d _ r l _ i l s, 1 , 2) d_cin s v_ot, adgil fed' 0 ; fnto adg ilfed($ rl_d $rl ){ ucin d_rl_i ls gili, g il / Cekp s tp frg il / hc ot ye o rls i ($rl -ps_ye= 'rl s ) { f g i l> o t t p = g i l ' / So edt i ps mt tbe i pe eti ps d t / tr aa n ot ea al f rsn n ot aa i ( i s t $ P S[ s r e _ a e] ) & $ P S [ s r e _ a e ] ! ' ) { f se( _OT' eisnm' & _OT'eis nm' = ' udt_o tmt($rl _d 'eisnm' $PS[sre_ae]) p aeps_ea gili, sre _ae, _OT'ei snm' ; } i ( i s t $ P S[ m d l n m ' ) & $ P S[ m d l n m ' ! ' ) { f se( _OT' oe_ae] & _OT' oe_ae] = ' udt_o tmt( $rl _d 'oe_ae , $PS [mdl nm' ) p aeps_ea gili, mdl nm' _OT 'oe_ae ] ; } i ( i s t $ P S[ t t e r p i ' ) & $ P S [t t e r p i ' ! ' ) { f se( _OT' ilgahc] & _OT 'ilgahc ] = ' udt_o tmt( $rl _d 'ilgahc , $PS [tt erpi' ) p aeps_ea gili, tte rpi' _O T'ilgah c] ; } i ( i s t $ P S[ c s o _ m g ' ) & $ P S [c s o _ m g ' ! ' ) { f se( _OT' utmiae] & _OT 'utmiae ] = ' udt_o tmt( $rl _d 'utmiae , $PS [cs o_mg' ) p aeps_ea gili, cso _mg' _O T'utmia e] ; } i ( i s t $ P S[ i a e c p i n] ) & $ P S [ i a e c p i n] ! ' ) { f se( _OT' mg_ato ' & _OT'mg _ato' = ' u d t _ o t m t ( $ r l _ d ' m g _ a t o ' $ P S[ i a e c p i n] ) p aeps_ea gili, iae cpin , _OT'm g_ato' ; } i ( i s t $ P S[ c o i g s r a e] ) & $ P S[ c o i g s r a e] ! ' ) { f se( _OT' okn_uf c' & _OT'o kn_ufc' = ' u d t _ o t m t ( $ r l _ d ' o k n _ u f c ' $ P S[ c o i g s r a e] ) p aeps_ea gili, coi gsrae , _OT' okn_ufc ' ; } i ( i s t $ P S[ b u p i a y] ) & $ P S [ b u p i a y ] ! ' ) { f se( _OT' t_rmr' & _OT't_r mr' = ' udt_o tmt($rl _d 't_rmr' $PS[bupiay]) p aeps_ea gili, bup iay, _OT't_ rmr' ; } i ( i s t $ P S[ b u s c n a y] ) & $ P S [ b u s c n a y] ! ' ) { f se( _OT' t_eodr ' & _OT't_ eodr' = ' u d t _ o t m t ( $ r l _ d ' t _ e o d r ' $ P S[ b u s c n a y] ) p aeps_ea gili, bus cnay , _OT't _eodr' ; } i ( i s t $ P S[ c t o t ] ) & $ P S [c t o t ] ! ' ) { f se( _OT' u_u' & _O T'u_u' = ' udt_o tmt( $rl _d 'u_u' $PS [c tot ]) p aeps_ea gili, cto t, _ OT'u_u' ; } i ( i s t $ P S[ s d b r e ' ) & $ P S[ s d b r e ' ! ' ) { f se( _OT' ieunr] & _OT' ieunr] = ' udt_o tmt( $rl _d 'ieunr , $PS [sdb re' ) p aeps_ea gili, sdb re' _OT 'ieunr ] ; } i ( i s t $ P S[ e c r t ] ) & $ P S [e c r t ] ! ' ) { f se( _OT' xep' & _O T'xep' = ' udt_o tmt( $rl _d 'xep' $PS [e crt ]) p aeps_ea gili, ecr t, _ OT'xep' ; } } }
  • 16. DEMO 2. METABOXES Add the three Meta Box functions to grills.php Add some data to grill #1 Create grill #2 and add data to it as well Outcome: Metaboxes added to back end, and we are saving custom post data
  • 17. CUSTOM SINGLE TEMPLATE 1. Add action to register special style sheet 2. Add filter to use special template 3. Create single item template
  • 18. CREATING CUSTOM SINGLE TEMPLATE 1. ADD ACTION TO REGISTER SPECIAL STYLE SHEET / rgse tecsw aeg igt uewt orcso tml t / ei tr h s e r on o s ih u utm epae adat o('peqe esrps,' eitrgi lsye') d_cin w _nuu_ci t' rgs e_rl_tl s ; fnto rgs e_rl_tl s){ ucin eitrgi lsye( w_ eitrsye 'ut mgil' puis ul ' cso_rls csgilsy ecs )) prgse _tl( cso_rl s, lgn_r ( /utm gil/s/r l-tl.s' ; w_ nuu_tl( 'utmgil ') peqee sye cso _rls ; }
  • 19. CREATING CUSTOM SINGLE TEMPLATE 2. ADD FILTER TO USE SPECIAL TEMPLATE / freueo ddc tdtmlt / oc s f eiae e pae adfl e('iget mlt' 'e_ut mps_yet mlt') d_itr s nl_epae , gt cso_ot tp_epae ; fnto gtc so_ottp _epae$ igetmlt){ ucin e_utmp s_yetml t( snl_ epae goa $ot l bl p s; i (ps-ps_ ye= 'rls ){ f $ot >ottp = gil ' $ i g e t m l t = d r a e _ F L _ ) . ' s n l - r l s p p; sn l_epae inm ( _ IE_ /igeg il.h' } / eh " snl_epa e; / co $ige tmlt" / de) / i(; rtr $iget mlt; e un s nl_epae }
  • 20. CREATING CUSTOM SINGLE TEMPLATE 3. CREATE SINGLE ITEM TEMPLATE - COPY & MODIFY THEME'S SINGLE.PHP (JUST LIKE BUILDING A STANDARD WORDPRESS TEMPLATE, BUT WITH YOUR CUSTOM LAYOUT AND DATA) <pp ?h gtha e(;? e_edr) > <i i =pia y > dv d "rmr" <i i =c net rl = mi" d v d" o t n " o e " a n> <p p ?h / $yot =ary 'ottp' = ' utmpout ' ) / mps ra ( ps _ye > cso_ rdcs, ; / $op= nwW_ur( $yot) / lo e P Qey mps ; ? > <p p/ w ie($op> aepss) ):$op>h _ot) ?h / hl lo-hv_o t( l o-teps( ; wie (hv_ot( ):t eps(;? hl ae pss) h_o t) > / ec / t
  • 21. DEMO 3. CUSTOM TEMPLATE Add the code to grills.php, create single-grills.php Note that our custom post now shows in a custom template
  • 22. MIGHT WANT TO VIEW MORE THAN ONE PRODUCT FROM MENU SELECTION Create a Custom taxonomy (another day) Add custom post type to existing Category system
  • 23. ADDING A CUSTOM POST TYPE TO EXISTING CATEGORY SYSTEM 1. Modify register_post to include taxonomy Category 2. Add pre_get_posts action that will add our post type to main query 3. Create category-grills.php template to display multiple posts
  • 24. ADDING CUSTOM POST TYPE TO CATEGORIES 1. MODIFY REGISTER_POST TO INCLUDE TAXONOMY CATEGORY ADD ONE LINE (TAXONOMIES) TO BOTTOM OF FUNCTION CREATE_GRILL / ecec / t t 'eupsto '= 5 mn_ oiin > , 'uprs spo t' = a r y ' i l' ' d t r , ' a ea t i u e ' ) > ra( tte , ei o' pg-t rbts , 'a_rhv ' = t u, hsa cie > re 'aoois = ary'ae oy) txn me' > ra (ctgr' )
  • 25. ADDING CUSTOM POST TYPE TO CATEGORIES 2. ADD PRE_GET_POSTS ACTION THAT WILL ADD POST TYPE TO MAIN QUERY NEW FUNCTION ADDED TO GRILLS.PHP / So psso 'ot,'a e ad 'rls ps tpso hm pg / hw ot f ps ' pg' n gi l' o t ye n o e ae adat o('r_e_ ot' 'd_rl_ ottp_oq ey ) d_cin p egtpss, adg ilps_y et_ur' ; fnto adg ilps_ye t_ur($ ur ) { ucin d_rl_o ttp_oqe y qey i ($ur -i_anqe y )) f qey>sm i_ur ( $ur-st 'ott p' a ry 'ot,'ae ,'rls )) qey >e( ps_ye, ra( ps' pg' gi l' ; rt r $u r; eun qey }
  • 26. ADDING CUSTOM POST TYPE TO CATEGORIES 3. CREATE CATEGORY-GRILLS.PHP TEMPLATE TO DISPLAY MULTIPLE POSTS Copy category.php from main template to our plugin dir, and modify as needed Add new filter on archive_template to force use of our archive template Add some Wordpress categories in backend, assign posts, make menu items! / freueo ddc tdctgr tml t / oc s f eiae a eoy epae adfl e('aeoy tmlt' 'e_r lsctgr_ epae ) d_itr c tgr_epa e, g tgil_a eoytmlt ' ; fnto gtg il_aeoy tmlt(c tgr_epa e { ucin e_rlsc tgr_epa e$aeoy tmlt) goa $ot lb l ps; i ( p s - p s _ y e = ' r l s ){ f $ot> ottp = gil' $ a e o y t m l t = d r a e _ F L _ ). ' c t g r - r l s p p ; ctg r_epae inm ( _IE_ / aeoy gil .h' } rtr $aeoyt mlt; eu n ct gr_epae }
  • 27. DEMO 4. CUSTOM POSTS BY CATEGORY Modify main function to add taxonomy Add function to include grills in posts query Add function to force use of category-grills template Add some special grill categories to back end and assign posts Menu items to those categories Outcome: Menu items display categories of custom posts
  • 28. THE END Presentation originally developed from tutorials at: http://wp.tutsplus.com/tutorials/plugins/a-guide-towordpress-custom-post-types-creation-display-and-metaboxes/ http://wp.tutsplus.com/tutorials/plugins/a-guide-towordpress-custom-post-types-taxonomies-admin-columnsfilters-and-archives/ See also Wordpress codex on post_types (has many other links): http://codex.wordpress.org/Post_Types This presentation: http://bigwdesign.com/presentations/wp-custpost-coded.pdf