0

I have an array of IDs that i send to query_posts to get the posts (which works fine) but it seems to always put the attachment(562) last even though it is the newest. Also tried title and ASC vs DESC but its always last?

$slide_args = array( 
    'post_type'   => 'attachment', 
    'post_status' => 'inherit',
    'fields'      => 'ids',
    'tax_query' => array(
        array(
            'taxonomy' => 'media_tag',
            'terms'    => 'new-work',
            'field'    => 'slug',
        )
    )
);

$slide_attachments = new WP_Query($slide_args);

$sticky_ids = get_option('sticky_posts');

$slideshow_posts = array_merge($slide_attachments->posts,$sticky_ids) ;

// creates Array ( [0] => 562 [1] => 479 [2] => 598 [3] => 686 ) 
// 562 is an attachment, the others are posts

$postsargs = array(             
    'orderby'       => 'date',
    'order'         => 'DESC',  
    'post_status'   => 'published',
    'post_type'     => array( 'attachment', 'post' ),
    'post__in'      => $slideshow_posts,
);

query_posts( $postsargs );

anyone know what might be going on? Best, Dc.

  • What happens if you change the second post_status arg to 'any'? – mrwweb May 24 '12 at 14:54
  • no change i'm afraid... – v3nt May 24 '12 at 15:03
  • Darn. I'm surprised the attachment shows up at all, considering that attachments never have the published status. – mrwweb May 24 '12 at 15:07
  • really? Used this several times but never had to use the orderby var before... – v3nt May 24 '12 at 15:09
  • See: the 'attachment' post_type description: codex.wordpress.org/Class_Reference/… – mrwweb May 24 '12 at 15:11
0

I think I got it. You're querying for sticky posts. Attachments can't be sticky at least by default. Hence, you're see the normal loop order when sticky posts are involved. So if you add this to your second args array:

'ignore_sticky_posts' => true

I think your problem should be resolved.

Here's the relevant codex section on that argument.

  • this has fixed it! So it was forcing the sticky posts to the top of the list as they were sticky and the media item wasn't. Cheers mrwweb! – v3nt May 28 '12 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.