0

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; ?>
4
  • "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
2

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
    )
  )
));   
2
  • 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. May 25 '12 at 16:17
  • Don't forget to mark yourself as the answer bud!
    – Jacksonkr
    Jul 30 '12 at 20:46

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.