php - Including post attachments (child posts?) in a single get_posts() call -
in wordpress template, i'm doing quick get_posts() call. i'd result 1 array of posts, where each post object in array contains array of post's attachments, (right need featured image, later may need more images). the reason: won't looping through result set in traditional template 'the_post_thumbnail()' - i'm setting quick ajax call, need 1 array data send client.
can't find in docs or online. i've got working solution, feels inefficient , i'm sure theres better way...
herse i'm doing now:
$ps = get_posts($args); // add post thumbnail post object foreach ( $ps $post ) : setup_postdata( $post ); $post->img = wp_get_attachment_url( get_post_thumbnail_id($post->id) ); endforeach; // output updated array json header('content-type: application/json'); echo json_encode($ps); die();
so again, want 1 get_posts() call returns post array, attachment ids included in each post object. possible?
thanks!
Comments
Post a Comment