Wordpress get attachment of post doesn't work -


i'm trying retrieve attachment of specific post, doesn't work moment. here code :

    $args = array(         'post_type' => 'attachment',         'posts_per_page' => -1,         'post_parent' => $id     );     $attachments = get_posts($args); 

where id id of post. i've tried new wp_query() didn't worked neither. both ways return empty result.

does have idea i'm doing wrong here ?

thanks

edit

ok, think know what's going wront. when using arguments get_posts function, return images uploaded through "add media" button in specific post.

so basically, let's on first post, i've uploaded images need future post. if apply request on first post, retrieve images, 1 don't use in post. if apply function post, because didn't uploaded file in post, function retrieve empty array.

does have idea how can retrieve images used in specific post ? not uploaded, integrated post or added custom field ?

thanks

when using get_posts fetch attachments, need set post_status inherit. also, check out get_children function:

$args = array(     'post_type' => 'attachment',     'post_mime_type' => 'image',     'numberposts' => -1,     'post_status' => 'inherit',     'post_parent' => $id ); $attachments = get_children( $args ); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -