WP_Query doesn't seem to filter with meta_query
-
I’ve added a loop to a template used for a single post, but WP_Query doesn’t seem to filter the posts collected according to their meta fields
I created two custom post types: “issue” and “article”.
“Issues” have post ids (obviously). And each “article” has a meta-field called “journal_article_in_issue” containing the post id of the issue to which they belong.I’m trying to use WP_Query to collect all the posts with both the post-type of “article” and an “in-issue” value equal to the current issue post id.
This is the code intended to act as a loop within the single-issue template. It does collect all the posts with the post_type of ‘article’, but it is collecting all the posts regardless of the value of the ‘journal_article_in_issue’ meta field.
<?php $issue_id=get_the_ID(); $post=get_post($issue_id); ?> <!-- do some stuff with the single issue's information --> <!-- display articles in issue --> <div class="journal-issue-contents"> <?php $article_query_args = array( 'post_type' => 'article', 'meta_query' => array( 'journal_article_in_issue' => $issue_id ) ); $article_query = new WP_Query($article_query_args); if($article_query->have_posts()) { while($article_query->have_posts()) { $article_query->the_post(); echo '<div>' . get_the_title() . '</div>'; } } ?> </div>
The example page is http://amosglenn.com/ssa/issue/january-june-2013/
Full template file is at http://pastebin.com/gX2D0X9r
Thanks!
-
esmi,
I modeled my code after the “Single Custom Field Handling” example on that page. I’m not seeing what I’m doing different.
Thanks.
Go and look at the “Single Custom Field Handling” example. Where are your key, value or compare parameters?
Thanks, esmi.
I’m quite embarrassed…
We all have days like that. 🙂
- The topic ‘WP_Query doesn't seem to filter with meta_query’ is closed to new replies.