Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
What happens if you change the second post_status arg to 'any'? –  mrwweb May 24 '12 at 14:54
    
no change i'm afraid... –  daniel Crabbe 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... –  daniel Crabbe May 24 '12 at 15:09
    
See: the 'attachment' post_type description: codex.wordpress.org/Class_Reference/… –  mrwweb May 24 '12 at 15:11
show 4 more comments

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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! –  daniel Crabbe May 28 '12 at 9:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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