Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Custom Post Types
Search
Jenny Wong
April 26, 2014
Technology
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Custom Post Types
A introductory guide to WordPress Custom Post Types. Presented at WordCamp Sheffield 2014
Jenny Wong
April 26, 2014
More Decks by Jenny Wong
See All by Jenny Wong
The Road Taken
missjwo
0
270
Why and how to do a Site Health Check
missjwo
0
130
Getting ready for PHP7.2
missjwo
0
2.7k
is it possible to build a truly diverse community?
missjwo
0
440
Going Backstage on Community Trends: Bug or Feature?
missjwo
1
280
We Didn’t Care About Diversity — What Happened Next Is Amazing!
missjwo
0
300
Building on WordPress for Enterprise
missjwo
0
120
Building an Accessible Community - AlterConf Dublin Edition
missjwo
0
130
Building an Accessible Community
missjwo
2
260
Other Decks in Technology
See All in Technology
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
2
700
「図書館」という名前のままでいいのか -Code4Lib JAPANカンファレンス2026 アンカンファレンス報告- / Code4Lib JAPAN Conference 2026: Unconference Report
ykiyota
0
160
株式会社シーエーシー エンジニア向け会社紹介資料
cac
0
57k
AIネイティブプロダクトで顧客価値を最大化するプロダクトエンジニアとFDEの協働
righttouch
PRO
0
230
The Agent Builder Loop from Daily Work to OSS
minorun365
PRO
3
130
【視聴者参加型!】AWSセキュリティアンチパターンクイズ
syoshie
1
490
プロダクト思考 × 基盤思考を AIで実現する Compound Engineering
tkc66buzz
1
320
多層防御と最⼩権限で実現する、安全なAIエージェント設計パターン
lycorptech_jp
PRO
1
260
AI時代のAPI品質を支えるガードレール / API Guardrails for API quality in the AI era
yokawasa
1
220
AI活用の現在地、 ちゃんと見えてますか?/XPfest-2026
visional_engineering_and_design
0
180
20260912_スクラムにジェネラリストは必要か
ryugen04
0
330
When Does a Local Qwen Start to Break
morshoto
0
200
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
450
Marketing to machines
jonoalderson
1
5.8k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
990
Designing for humans not robots
tammielis
254
26k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
WENDY [Excerpt]
tessaabrams
13
39k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Utilizing Notion as your number one productivity tool
mfonobong
4
580
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Technical Leadership for Architectural Decision Making
baasie
3
560
New Earth Scene 8
popppiees
3
2.5k
Transcript
Hello WC Shef+ield! Jenny Wong : Web Developer : @miss_jwo
Custom Post Types Jenny Wong : Web Developer : @miss_jwo
Fast Talker Feel free to ask me to slow down.
Its good for me.
Content The most important thing about a site.
Post Types WordPress deals with all the different type of
content by de+ining them based on what they are. ! The de+initions are called Post Types.
Post Types ! •Post •Page •Attachments •Revision
•Nav Menus } Defaults
Custom Post Types CPT for short.
Post Types ! •Post •Page •Attachments •Revision
•Nav Menus
Custom Post Types • Post • Page •
Attachments • Revision • Nav Menus •News •Staff … anything from Jen’s head
Why?
Advantages •Hides content from the default query •Management of
content is easier •Improved user interface & usability •The ability to use custom templates
Disadvantages •Performance issue with querying a large table
•If content doesn’t easily +it the post type tables then issues can occur.
Where do CPTs live? The Options
Theme •CPT attached to the theme •Activate Theme &
CPT will appear •Deactivate theme: • User cannot access their CPT data • Data still stored in the database
Plugin • Functionality is separate to the design of
the website •Can activate new theme without functionality disappearing •Plugins can be deactivated
Must Use Plugin mu plugin for short.
Must Use Plugin
Must Use Plugin https://codex.wordpress.org/Must_Use_Plugins
The Code
Register New CPT
Register New CPT <?php ! ! register_post_type( $post_type, $args );!
! $post_type! - Name of post type! $args! ! ! -! An array of arguments.! ! ! ! !
Register New CPT <?php ! ! register_post_type( $post_type, $args );!
! $post_type! - Name of post type! $args! ! ! -! An array of arguments.! ! Full arguments list: ! https://codex.wordpress.org/Function_Reference/register_post_type#Arguments! ! !
CPT in action <?php ! ! function cpt_wcsheff () {!
! ! $args = array( … );! ! ! register_post_type(‘speakers’, $args );! ! }! ! add_action( 'init','cpt_wcsheff');! !
Categories & Tags
Categories & Tags ! Default taxonomy: • category
• post_tag
Categories & Tags function cpt_wcsheff () {! ! …! !
register_post_type(‘speakers’, $args );! ! ! register_taxonomy_for_object_type( ! ! ! 'category', 'speakers' ! ! );! ! ! register_taxonomy_for_object_type( ! ! ! 'post_tag', 'speakers' ! ! );! }!
Custom Taxonomies
Custom Category $post_types = array(‘speakers’);! ! $category_args = array(! !
'hierarchical' => true ! );! ! register_taxonomy( ! ! 'custom_cat', ! ! $post_types,! ! $category_args! );! !
Custom Tag $post_types = array(‘speakers’);! ! $category_args = array(! !
'hierarchical' => false ! );! ! register_taxonomy( ! ! 'custom_tag', ! ! $post_types,! ! $category_args! );! !
Custom Taxonomies https://codex.wordpress.org/ Function_Reference/register_taxonomy
Templating
Custom Templates ! archive-‐$post_type.php archive.php ! single-‐$post_type.php
single.php ! taxonomy-‐$taxonomy-‐$term.php taxonomy-‐$taxonomy.php taxonomy.php
Condition Tags ! is_post_type_hierarchical( $post_type ); ! is_post_type_archive( $post_type
); ! post_type_exists( $post_type ) ; !
Common Issues
Permalinks URL that points to a particular location !
http://codex.wordpress.org/Using_Permalinks
Permalinks Issue: 404 error on a single CPT page
Flushing Permalinks ATTENTION: You should *NEVER EVER* do this on
every page load!!
Flushing in a plugin function cpt_wcsheff() {! register_post_type( ... );!
}! ! ! function my_rewrite_flush() {! cpt_wcsheff();! flush_rewrite_rules();! }! ! ! register_activation_hook( ! ! __FILE__, ! ! 'my_rewrite_flush' ! );! ! !
Flushing in a theme function cpt_wcsheff() {! register_post_type( ... );!
}! ! ! function cpt_wcsheff_rewrite_flush() {! flush_rewrite_rules();! }! ! add_action( ! ! 'after_switch_theme', ! 'cpt_wcsheff_rewrite_flush' ! );! ! !
Permalinks https://codex.wordpress.org/Function_Reference/ register_post_type#Flushing_Rewrite_on_Activation
Slugs
Slugs ! example.com/permalinks/slugs ! example.com/slugs !
CPT Naming
CPT Naming Permalink Structure: ! $custom_post_type =
‘wc_shef+ield’; $custon_tax = ‘wc_shef+ield’; ! example.com/$custom_post_type/post_slug ! example.com/$custom_tax/another_slug
Questions?
Ask me later Jenny Wong : Web Developer : @miss_jwo