I am trying to retrieve attachments that are attached to my current post. This is the code that I am trying to use. What I’m attempting to do is query all of my posts that are of custom post type business-manager. From within that loop I am starting another query to retrieve the attachments associated with that post. If I var dump the $attachment variable I get an empty array. If I pass the array for attachment variable into get_posts($args) then do a var dump I can retrieve all of the images. How can I do this using a new WP_Query object?
$my_query = new WP_Query( array(
'post_type' => 'business-manager',
'posts_per_page' => 1,
'tax_query' => array(
'taxonomy' => 'business-type',
'field' => 'slug',
'terms' => 'featured'
)
) );
$attachment = new WP_Query( array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $my_query->post->ID
) );