Aaron Snyder
Aaron Snyder

Reputation: 177

Display all posts from latest taxonomy in wordpress

I am creating a newspaper website that will have Volumes and Issues. Volumes increment yearly, issues increment weekly. I have created a custom post type of article with a taxonomy of issue.

Currently the code below will get the most recent post from the article with the most recent issue taxonomy. I want it to get all of the posts from the most recent issue. I figured out I can get the next post by changing $issue[0]->slug to $issue[1]->slug. I realize I just need a loop but I cant quite figure it out.

Your help is appreciated.

<?php
$issue = get_terms('issue','orderby=none&order=DESC');
$latest_edition = $issue[0]->slug;

query_posts('&post_type=article&gdsr_sort=thumbs&gdsr_order=desc&issue='. $latest_edition) . '&showposts=99'; ?>

Upvotes: 0

Views: 832

Answers (2)

Anahit Ghazaryan
Anahit Ghazaryan

Reputation: 690

Thx for the answer @hohner.It really helped me to go ahead with my issue. @Aaron Snyder for the complete result you can add some loop with your taxonomy information like this for showing all posts results

$latest_edition = $issue[0]->slug;
$latest_edition = $issue[0]->term_id;
$postsart = get_posts(array(
'showposts' => -1,
'post_type' => 'articles',
'tax_query' => array(
array(
'taxonomy' => 'articles-tax',
'field' => 'term_id',
'terms' => $latest_edition)
))
);

Try it helped me and tell if it helped you or not

Upvotes: 0

hohner
hohner

Reputation: 11588

You're not looping through your posts. You need to do something like:

// Returns an array issues
$issue = get_terms('issue','orderby=none&order=DESC');

// You want the most recent issue
// i.e. that which has an array key of 0
$latest_edition = $issue[0]->slug;

// Return all the posts for this issue
query_posts('&post_type=article&gdsr_sort=thumbs&gdsr_order=desc&issue='. $latest_edition) . '&showposts=99';

// Loop through each post
while ( have_posts() ) : the_post();
   // Echo out whatever you want
   echo '<li>';
   the_title();
   echo '</li>';
endwhile;

Upvotes: 3

Related Questions