Custom Fields with get_post()

You already know the ID, so just use it: $customField = get_post_meta($my_id, “_mcf_customField”, true); But only for reference, if you want to get the ID from the object: $customField = get_post_meta($post_id->ID, “_mcf_customField”, true);

Cannot get grandparent object

just a small error. To get the parent and Grandparent objects, you need to get_post them also. The property “post_parent” only gives you the ID of that post, not the post_object itself. So you change your code like this: <?php $current = get_post($post->ID); //Conditional to be sure there is a parent if($current->post_parent){ $grandparent = get_post($current->post_parent); … Read more

Using apply_filters(‘the_content’, $custom_query->post_content) alters output

the_content filter takes only one parameter – $content, so you can’t check what post this $content comes from. So if the plugin Team performs incorrect checks (it can for example use is_singular( <POST_TYPE> )), then it will modify all contents printed on single team member page. You’ll have to check what functions are assigned to … Read more

WordPress function to get term or post object by id

get_queried_object() will get the currently queried ‘thing’ from the main query as an object. That could be a WP_Post, WP_Term, or WP_Post_Type (for post type archives) object, but I don’t think that’s quite what you’re asking for and wouldn’t be useful in AJAX. Other than that there isn’t a function for exactly what you’re asking … Read more

Disable block from editor based on post type

You can use the allowed_block_types hook: <?php function wpse_allowed_block_types($allowed_block_types, $post) { // Limit blocks in ‘post’ post type if($post->post_type == ‘post’) { // Return an array containing the allowed block types return array( ‘core/paragraph’, ‘core/heading’ ); } // Limit blocks in ‘page’ post type elseif($post->post_type == ‘page’) { return array( ‘core/list’ ); } // Allow … Read more

How to get the image EXIF date/time and use it for the WP post date/time

PHP has a function for this purpose: exif_read_data I used this image for testing. Try this code for your purpose: add_action( ‘add_attachment’, ‘create_post_from_image’ ); function create_post_from_image( $id ) { if ( wp_attachment_is_image( $id ) ) { $image = get_post( $id ); // Get image height/width for auto inserting the image later @list( $width, $height ) … Read more

Difference between the_content() and get_post()?

post_content is a property of the WP_Post object. WP_Post is an object representing the post data from the database. So post_content contains the raw content as stored in the database. the_content() is a template tag that displays the content of the current post. The ‘current post’ is whatever the global $post variable is set to … Read more