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.

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

1 Answer 1

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.

1
  • 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! Commented May 28, 2012 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.