Home › Forums › Back End › Only Display posts with specific custom field value within string or array
- This topic is empty.
-
AuthorPosts
-
August 3, 2013 at 7:11 am #145580EsquiveliaParticipant
Ok so I have everything displaying correctly but if there are terms other than the conditional term ‘Non-Marine’ within the field ‘value’ for the custom field “item_tags” it does not display those.
Basically I’m looking for posts with :
1. Custom post_type – ait-dir-item
2. Custom field location – annapolis
3. Custom field item_tags – Non-Marine (this value is within other terms seperated by commas)I’m also not sure if these values are strings or arrays?
Here is the code I have so far:
<?php $args = array( 'post_type' => 'ait-dir-item', 'meta_query' => array( array( 'key' => 'location', 'value' => 'annapolis' ), array( 'key' => 'item_tags', 'value' => 'non-marine' ) ), 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 300 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); the_title('<h3 class="entry-title">', '</h3>'); echo '<div class="entry-content">'; the_content(); echo '</div>'; endwhile; ?>
Thanks for any input!
Cory-
August 3, 2013 at 5:38 pm #145621SenffParticipantI think you’re doing it right so I’m not sure why it isn’t working.
You might want to add a “compare” in the meta_query array, who knows that might make a difference. See http://codex.wordpress.org/Class_Reference/WP_Meta_Query for details.
August 4, 2013 at 8:25 am #145643EsquiveliaParticipantSenff,
Thanks man! Working now!
<?php $args = array( 'post_type' => 'ait-dir-item', 'meta_query' => array( array( 'key' => 'location', 'value' => 'annapolis' ), array( 'key' => 'item_tags', 'value' => 'Non-Marine', 'compare' => 'LIKE', ) ), 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 300 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); the_title('<h3 class="entry-title">', '</h3>'); echo '<div class="entry-content">'; the_content(); echo '</div>'; endwhile; ?>
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.