WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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(); ?>

    <creator>Artist name</creator>
    <title>Track 1</title>

<?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
@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
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(
        'meta_key'   => 'mixtape',
        'meta_value' => (string)$mixtape_id
share|improve this answer
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! – Jacksonkr Jul 30 '12 at 20:46
thanks! for that – Tallboy Jul 30 '12 at 20:50

Your Answer


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.