Ryan Kanner (@CodeProKid)
Post
Term
User
Comment
Post
Page
Attachment
Menu-items
Categories
Tags
Menus
Ping
Object 1
Object 2
Examples
Advantages
Disadvantages
Object 1
Object 2
Examples
Advantages
Disadvantages
Object 3
Object 3
Examples
Advantages
Disadvantages
Object 4
Object 1
Object 2
WP_Post
wp_insert_post($args, $wp_error);
get_post($id, $output, $filter);
wp_update_post($args, $wp_error);
wp_delete_post($id, $force);
get_posts($args);
WP_Query
WP_Term
wp_insert_term($term, $tax, $args);
get_term($term, $tax, $output, $filter);
wp_update_term($term_id, $tax, $args);
wp_delete_term($term, $tax, $args);
get_terms($args);
WP_Term_Query
WP_User
wp_insert_user($userdata);
get_userdata($user_id);
wp_update_user($userdata);
wp_delete_user($userid, $reassign);
get_users($args);
WP_User_Query
WP_Comment
wp_insert_comment($commentdata);
get_comment($comment, $output);
wp_update_comment($commentdata);
wp_delete_comment($comment_id, $force);
get_comments($args);
WP_Comment_Query
add_option($option, $value, $autolaod);
get_option($option, $default);
update_option($option, $value, $autoload);
delete_option($comment_id, $force);
comment | post | term | user | Option | |
---|---|---|---|---|---|
class | WP_Comment | WP_Post | WP_Term | WP_User | N/A |
read | get_comment() | get_post() | get_term() | get_userdata() | get_option |
create | wp_insert_comment() | wp_insert_post() | wp_insert_term() | wp_insert_user() | add_option() |
update | wp_update_comment() | wp_update_post() | wp_update_term() | wp_update_user() | update_option() |
delete | wp_delete_comment() | wp_delete_post() | wp_delete_term() | wp_delete_user() | delete_option() |
querying | get_comments() | get_posts() | get_terms() | get_users() | N/A |
query class | WP_Comment_Query | WP_Post_Query | WP_Term_Query | WP_User_Query | N/A |
subtypes | Kinda (pings) | yes (post types) | yes (taxonomies) | no | Kinda (widgets) |
metadata | yes | yes | yes | yes | No |
Comment | Post | Term | User | Option | |
---|---|---|---|---|---|
Strength | The built in connection to posts is nice. | Most robust storage model. | Supports many to many connections, Good for related data on posts. | Does a good job modeling data related to a human being. | Most freeform option. Easy to access the data from any context. |
Weakness | Model is very opinionated, core fields are very specific to public facing comments. | Could be overkill in some cases. | Heavily extending this type can lead to a poor data management experience in the admin. | Tied to site access roles and capabilities. | Not scalable for many entries. |
Post Type Label
Term Archive
Term Description
List of terms in taxonomy
Grab queried term from main query, apply active class
Title
Term
Meta
the_content
Terms
meta / open repeater
meta / open repeater
meta / menu_order
add_action( 'updated_post_meta', 'my_calback', 10, 4 );
function my_callback( $meta_id, $object_id, $meta_key, $meta_value ) {
if ( 'total_homes' !== $meta_key ) {
return;
}
wp_update_post( [
'ID' => absint( $object_id ),
'menu_order' => absint( $meta_value ),
] );
}
// Slowwwww
$portfolio_items = new WP_Query( [
'post_type' => 'portfolio',
'meta_key' => 'total_homes',
'orderby' => 'meta_value_num',
] );
// Fast!
$portfolio_items = new WP_Query( [
'post_type' => 'portfolio',
'orderby' => 'menu_order',
] );
Author box. Grabs data from the user profile for the author of the article.
CTA box that is changed out every few weeks/months. Also A/B tested. Pulled from a custom post type.
Related posts module that is customized per term. Managed on the term edit screen where you select a few posts to feature.
Managed as a menu, and added to the bottom of all posts in a few post types.
Static CTA that never changes.
Commenting policy stored in an option, managed in site settings.
This data is very closely tied to a user's profile. It's not relevant to anything else.
There will likely be a lot of these, and they need to be shared across different types. There are also a fair amount of settings needed here.
This will change pretty often, and are directly tied to the term the post is in.
This is just a list of links to existing entities. The built in menu management does this really well.
This never changes, let's make it static.
This needs to be a global setting, as it spans all types. Need one central spot for updates.
(what happens if you mess up)
add_action( 'updated_post_meta', 'my_calback', 10, 4 );
function my_callback( $meta_id, $object_id, $meta_key, $meta_value ) {
if ( 'key_to_migrate' !== $meta_key ) {
return;
}
wp_set_post_terms( $object_id, $meta_value, 'meta-tax', true );
}
add_filter( 'get_post_metadata', 'my_callback', 10, 4 );
function my_callback( $check, $object_id, $meta_key, $single ) {
if ( 'key_to_migrate' !== $meta_key ) {
return $check;
}
$terms = wp_get_object_terms( $object_id, 'meta-tax', [
'fields' => 'names',
] );
if ( true === $single ) {
return $terms[0];
}
return $terms;
}
Ryan Kanner (@CodeProKid)