Articles of get post

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 […]

What is an alternative to get_page_by_title()?

I’m coding a theme where I want to display information in the footer that’s only available on a template page. I have been using get_page_by_title() which works well if you know what the page will be called, but in my opinion it’s not very dynamic, it’s impossible to predict what a user will name a […]

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’, […]

get_post() vs global $post or $GLOBAL

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 […]