jchristopher / attachments

[WordPress Plugin] Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
wordpress.org/extend/plugins/attachments/
GNU General Public License v2.0
241 stars 78 forks source link

Retrieve Attachments Outside The Loop doesn't work #189

Open im4aLL opened 4 years ago

im4aLL commented 4 years ago

For custom post type - retrieving attachments don't work

$query = new WP_Query([
    'post_type'        => 'news',
    'posts_per_page'   => 5,
]);

echo '<pre>';
print_r($query->posts);
echo '</pre>';

wp_reset_query();

$attachments = new Attachments( 'attachments', 13 ); // post ID 13 has 4 attachments
echo $attachments->exist() ? 'yes' : 'no'; // result is - no. Thought it has data!

Temporary fix