I am presently working on a WordPress Journal Theme and I would like to know the best way to
1. Sort the articles (a custom post type) based on Volumes and Issues (e.g., Volume 1 Issue 1, Volume 1 Issue 2 or Volume 1 Issue 3).
2. Display the current issue on the homepage (e.g., Volume 1 Issue 3)
What I have done so far
1. I created a custom taxonomy (Volume and Issues) and a custom field type (taxonomy) using ACF which I linked together. With the code below, I was able to display all posts in the taxonomy irrespective of whether they are in Volume 1 Issue 1, Volume 1 Issue 2 or Volume 1 Issue 3.
<?php
$homepageArticles = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'article',
'meta_key' => 'current_issue',
'orderby' => 'meta_value',
));
while($homepageArticles->have_posts()){
$homepageArticles->the_post(); ?>
<div class="j-header shadow">
<div class= "j-category"> <?php the_field('article_category'); ?>
</div>
<div class="j-section">
<div class="j-article-thumbnail ">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium'); ?></a>
</div>
<div class="j-article-excerpts jp-excerpt ">
<div class="j-title">
<h1 class='j-title'><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h1>
</div>
<div class="j-authors"> <span>By: </span>
<?php the_field('authors'); ?></div>
<div id="mini-navbar">
<ul class="mini-navbar">
<li><a href="#">Abstract</a></li>
<li><a href="<?php the_permalink(); ?>">HTML Full Text</a></li>
<li><a href="<?php the_field('uplaod_pdf'); ?>">PDF</a></li>
</ul>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
<?php
} wp_reset_postdata();
?>
I also tries filtering the posts using meta_query using the second code but I got confused when it was time for me to compare the variables I created`
$currentIssue = get_field('current_issue'); $pastIssue = get_field('current_issue');
$homepageArticles = new WP_Query(array( 'posts_per_page' => -1, 'post_type' => 'article', 'meta_key' => 'current_issue', 'orderby' => 'meta_value', 'meta_query' => array( array( 'key' => $currentIssue, 'compare' => '>', 'value' => $pastIssue )
))); while($homepageArticles->have_posts()){ $homepageArticles->the_post(); ?> <div class="j-header shadow"> <div class= "j-category"> <?php the_field('article_category'); ?> </div> <div class="j-section"> <div class="j-article-thumbnail "> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium'); ?></a> </div> <div class="j-article-excerpts jp-excerpt "> <div class="j-title"> <h1 class='j-title'><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h1> </div> <div class="j-authors"> <span>By: </span> <?php the_field('authors'); ?></div> <div id="mini-navbar"> <ul class="mini-navbar"> <li><a href="#">Abstract</a></li> <li><a href="<?php the_permalink(); ?>">HTML Full Text</a></li> <li><a href="<?php the_field('uplaod_pdf'); ?>">PDF</a></li> </ul> </div> </div> </div> <div class="clearfix"></div> </div>
`
I would also like to know if there is a better way to sort articles based volumes and Issues in WordPress