8. @randyhoyt #orlandowordcamp
University Course
Posts Pages Assignments
11. @randyhoyt #orlandowordcamp
wp_posts
ID post_type post_title
1 post Hello, world!
2 page Sample Page
231 rrh_assignment Final Exam
12. @randyhoyt #orlandowordcamp
wp_posts
ID post_type post_title
1 post Hello, world!
2 page Sample Page
231 rrh_assignment Final Exam
Structured Data in WordPress
http://randyhoyt.com/wcto
13. @randyhoyt #orlandowordcamp
Shopping Center
Stores
Posts Pages
Sales Jobs
14. @randyhoyt #orlandowordcamp
Shopping Center
Stores
Posts Pages
Sales Jobs
17. @randyhoyt #orlandowordcamp
Storing Relationships
1. Post Meta Field
2. Custom Relationship Table
3. Post Parent Field
18. @randyhoyt #orlandowordcamp
1. Post Meta Field
Talks
Speakers
Posts Pages
24. @randyhoyt #orlandowordcamp
Library: Custom Meta Boxes
http://r2h.me/wpcmb
Custom Meta Boxes allow you to build clean, understandable
interfaces for entering metadata. There’s a ton of field options:
text, textarea, checkbox, dropdown list, WYSIWYG, and more.
31. Retrieve speaker ID from custom field
$speaker_id = get_post_meta($post->ID,
"speaker", true);
Retrieve speaker info from ID
$speaker = get_post($speaker_id);
Display speaker title
echo $speaker->post_title;
Retrieve link to speaker from ID
$speaker_link = get_permalink($speaker->ID);
33. Retrieve talks with speaker ID in custom field
$talks = get_posts( array(
'post_type' => 'rrh_talk',
'meta_key' => 'speaker',
'meta_value' => $post->ID
));
Loop through all the talks; display talk title
foreach($talks as $talk) {
echo $talk->post_title;
}
35. @randyhoyt #orlandowordcamp
2. Relationship Table
Movies
People
Posts Pages
36. @randyhoyt #orlandowordcamp
2. Relationship Table
Movies
People
Posts Pages
37. @randyhoyt #orlandowordcamp
Custom Relationship Table
wp_posts <relationship>
wp_postmeta
ID post_type post_title to_id
post_id from_id
meta_key character
meta_value
37 movie Star Wars 37
38 38
speaker Han
37 Solo
38 person Harrison Ford
38. @randyhoyt #orlandowordcamp
Plugin: Posts 2 Posts
http://r2h.me/p2p
This plugin provides functions developers can use to create
many-to-many relationships between posts of any type:
posts, pages, and custom post types.
41. @randyhoyt #orlandowordcamp
Custom Relationship Table
wp_posts
ID post_type post_title
37 person Harrison Ford
38 movie Star Wars
wp_p2p wp_p2pmeta
p2p_id to_id from_id type p2p_id meta_key meta_value
1 37 38 person_to_movie 1 role Lead Actor
1 character Han Solo
46. @randyhoyt #orlandowordcamp
3. Post Parent Field
Groups
Posts Pages
Meetings
47. @randyhoyt #orlandowordcamp
wp_posts
ID post_type post_title post_parent
2 page About 0
231 page Location & Venue 2
256 page Developer Hack Day 2
347 page Contact 2
48. @randyhoyt #orlandowordcamp
wp_posts
ID post_type post_title post_parent
2 page About 0
156 revision About 2
157 revision About 2
158 revision About 2
49. @randyhoyt #orlandowordcamp
wp_posts
ID post_type post_title post_parent
15 forum Book Discussions 0
78 topic Favorite Tolkien Characters? 15
123 reply Reply To: Favorite Tolkien … 78
bbPress
http://bbpress.org/
50. @randyhoyt #orlandowordcamp
Subordinate Post Type Helpers
http://wordpress.org/extend/plugins/subordinate-post-type-helpers/
This plugin provides a number of helpers functions to aid in the
creation of subordinate relationships between two post types,
one-to-many relationships in which posts of one type are children
of another.
51. @randyhoyt #orlandowordcamp
Subordinate Post Type Helpers
http://wordpress.org/extend/plugins/subordinate-post-type-helpers/
This plugin provides a number of helpers functions to aid in the
creation of subordinate relationships between two post types, one-
to-many relationships in which posts of one type are children of
another.
register_sub_post_type('meeting', $args, 'group')
;
53. Register meetings as a regular post type
register_post_type('meeting', $args)
Register meetings as a subordinate post type
register_sub_post_type('meeting', $args, 'group')
65. <script>
function list_meetings(display)
{
...
}
JavaScript function in page
</script>
Create JavaScript function on the Edit Group page
66. <script>
var display = ...
var win = window.dialogArguments →
|| opener || parent || top;
win.list_meetings(display);
</script>
Call that JavaScript function from the iframe
67. <script>
function list_meetings(display)
{
jQuery('#list_meetings).empty() →
JavaScript function .append(display);
in page
tb_remove();
}
</script>
That function inserts the list into the Edit Group page
69. Register meetings as a regular post type
register_post_type('meeting', $args)
Register meetings as a subordinate post type
register_sub_post_type('meeting', $args, 'group')
70. Retrieve meetings for a group
$meetings = get_posts( array(
'post_type' => 'mythsoc_meeting',
'post_parent' => $post->ID
));
Loop through all the meetings; display meeting title
foreach($meetings as $meeting) {
echo $meeting->post_title;
}
71. @randyhoyt #orlandowordcamp
Storing Relationships
1. Post Meta Field
2. Custom Relationship Table
3. Post Parent Field