Disable block from editor based on post type

I’ve made a Gutenberg block which is only appropriate to show on hierarchical post types, so I want to disable it from the block inserter for non-hierarchical post types. I thought about how to achieve this in PHP, but the WordPress documentation on registering blocks seems to suggest that blocks should be registered in PHP … Read more

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

I currently have the following working function. 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) = getimagesize(get_attached_file($id)); $post = array( // Set image title as post title ‘post_title’ => $image->post_title, // Set post to draft for details ‘post_status’ => ‘draft’, … Read more

Elegant way to include only published posts with get_objects_in_term()?

The obvious way is to iterate through the resulting array of IDs, get_post for each and test against post_status == ‘publish’. But I wonder whether this could cause memory issues since get_post will attempt by default to cache each result? Short of a custom SQL join, are there any surprise args one can pass to … Read more

Difference between the_content() and get_post()?

I’m working on tweaking a theme and I need to explode the post content to remove some text. The following code is what I am using: $custom_Get_Post_Title = explode(‘|’,get_post()->post_content); echo “<h4>” . $custom_Get_Post_Title[0] . “</h4>”; echo “<p>” . $custom_Get_Post_Title[1] . “</p>”; Originally, the developer was using the follow code to display the post content, but … Read more

get_post() vs global $post or $GLOBAL[‘post’]

I’m writing a widget plugin and need access to post information. I’ve seen people using 3 different approaches: global $post; if ( isset( $GLOBALS[‘post’] ) ) $post = $GLOBALS[‘post’]; $post = get_post(); This post explains the difference between the first two solutions. Can you please confirm that a call to get_post() without args does the … Read more