Skip to content

Instantly share code, notes, and snippets.

@quawn
Last active April 11, 2024 22:22
Show Gist options
  • Save quawn/7770186 to your computer and use it in GitHub Desktop.
Save quawn/7770186 to your computer and use it in GitHub Desktop.
WP: Check if image attached to the post
<?php
$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
if ( $attachments ) {
// do conditional stuff here
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment