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.

This code isn't echoing out anything, even though I'm 100% positive $mixtape_id is set to an integer which corresponds to one of the posts within the 'mixtapes' custom post type

$query = new WP_Query(array(
  'post_type'      => 'mixtapes',
  'p'              => (int)$mixtape_id,
  'posts_per_page' => -1,
  'orderby'        => 'meta_value_num',
  'meta_key'       => 'track_number'
));

while ( $query->have_posts() ) : $query->the_post(); ?>

<track>
    <location>track1.mp3</location>
    <creator>Artist name</creator>
    <title>Track 1</title>
</track>

<?php endwhile; ?>
share|improve this question
    
"even though I'm 100% positive $mixtape_id is set to an integer" ... did you var_dump? –  kaiser May 25 '12 at 7:59
    
yes i typed it in manually with a number. I figured it out though, i used a different loop –  Tallboy May 25 '12 at 8:24
1  
@Tallboy - you mean you found the issue? If so, post it as an answer... –  brasofilo May 25 '12 at 9:46
    
It mainly has to do with my specific setup instead of a problem i was typing (although that code above should definitely have worked). ill put what i actually typed though –  Tallboy May 25 '12 at 16:10
add comment

1 Answer

up vote 1 down vote accepted

I fixed it by doing it a different way

$query = new WP_Query(array(
  'post_type'      => 'tracks',
  'posts_per_page' => -1,
  'orderby'        => 'meta_value_num',
  'meta_key'       => 'track_number',
  'meta_query'     => array(
    array(
        'meta_key'   => 'mixtape',
        'meta_value' => (string)$mixtape_id
    )
  )
));   
share|improve this answer
1  
p.s. you should use a more unique variable name than $query, which is far too generic. I would use something like $mixtape_query. –  Chip Bennett May 25 '12 at 16:17
    
Don't forget to mark yourself as the answer bud! –  Jackson Jul 30 '12 at 20:46
    
thanks! for that –  Tallboy Jul 30 '12 at 20:50
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.