How do I test whether there are any images attached to a post?
I'm using the gallery shortcode, but I want to put it in a conditional so the surrounding styling isn't displayed if the gallery is empty.
|
How do I test whether there are any images attached to a post? I'm using the gallery shortcode, but I want to put it in a conditional so the surrounding styling isn't displayed if the gallery is empty. |
|||
|
|
|
You can check if an attachment for the given post exists with the get_posts function. This will create a new sql query - so there could be a performance issue.
|
|||
|
|