0

i have a post type called directory_listing, i have a taxonomy called 'place' and I have terms in that tax for place1 and place2. I need to display all the 'directory_listing' posts that use the term place2 of taxonomy 'place' in a custom page template.

this is as far as i got, i am lost.

<?php
$pages = get_posts(array(
  'post_type' => 'directory_listing',
  'numberposts' => -1,
  'tax_query' => array(
    array(
      'taxonomy' => 'place',
      'field' => 'slug',
      'terms' => ('place2'),
      'include_children' => false
    )
  ))
);

foreach ($pages as $page) {
      echo $pages->post_title . '<br/>';
      echo $pages->post_content . '<br/>';
      echo $pages->slug . '<br/><br/>';
}
?>
1
  • numberposts is long since deprecated. Use posts_per_page and the parenthesis around the-damn-bar are not necessary.
    – s_ha_dum
    May 23 '14 at 16:34
0

Why that $pages suddenly became $myposts!!? Anyway, I really don't see any big issues with your code, however, you can try this..

<?php
$pages = get_posts(array(
  'post_type' => 'directory_listing',
  'posts_per_page' => -1,
  'tax_query' => array(
    array(
      'taxonomy' => 'place',
      'field' => 'slug',
      'terms' => 'place1',
      'include_children' => false
    )
  ))
);

foreach ($pages as $page) {
      echo $page->post_title . '<br/>';
      echo $page->post_content . '<br/>';
      echo $page->slug . '<br/><br/>';
}
?>
4
  • ahh yes I just caught that, tired eyes i suppose. ThankYou
    – Joe
    May 23 '14 at 16:40
  • Now, say i need to populate the 'terms' specifically to each page. would using a custom field writing to that area work?
    – Joe
    May 23 '14 at 16:42
  • @Joe Can you please explain a bit more on what you are trying to achieve? If you want to display archive for a specific term in a specific page, you can create a page template containing a loop to display posts from that term. Or even better, take advantages of Template Hierarchy codex.wordpress.org/…
    – Abhik
    May 23 '14 at 16:46
  • Abhik, I just want to have a place for the user making the page to add the term data, so above where is says place1, from the wp page editor. Like if there was a custom field on the page editor where they could just type 'place1' so that page would give all the results using that term. Does that help? I know you cant echo a custom field shortcode in place of 'place1' in an array.
    – Joe
    May 23 '14 at 17:20

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.