Q1 – Is there a difference between these 2? – Post Metadata and Queried Object.
Yes.
And I won’t go into a detailed explanation (e.g. what a post metadata is), but these should help you for what you’re trying to do:
-
Post metadata are saved in the
wp_postmeta
table. (Note though, the table prefix might be different in your case, butwp_
is the default.) -
The queried object in question refers to the post object/data which is retrieved from the
wp_posts
table, which contains fields likeID
,post_type
andcomment_status
— the one you’re trying to change.
So if you want to set the comment status of a post, there’s no need to add a custom metadata to the post. Just use wp_update_post()
.
Q2 – How do I set the default comment status for
sfwd-essays
post types toopen
?
Not sure if there’s a specific setting for that during post type registration, but there’s a hook you can use: get_default_comment_status
. For example for your post type:
add_filter( 'get_default_comment_status', function ( $status, $post_type ) {
// Set to open if post type = sfwd-essays
return ( 'sfwd-essays' === $post_type ? 'open' : $status );
}, 10, 2 );