Last active
January 19, 2022 13:28
-
-
Save ravismakwana/6bc3ebec4937a61f3275447b225b1e89 to your computer and use it in GitHub Desktop.
List Custom Posts with Custom Taxonomy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$custom_terms = get_terms('career_category'); | |
foreach($custom_terms as $custom_term) { | |
wp_reset_query(); | |
$args = array('post_type' => 'career', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'career_category', | |
'field' => 'slug', | |
'terms' => $custom_term->slug, | |
), | |
), | |
); | |
$loop = new WP_Query($args); | |
if($loop->have_posts()) { | |
echo '<h2 class="cat-heading">'.$custom_term->name.'</h2><ul class="job-listing">'; | |
while($loop->have_posts()) : $loop->the_post(); | |
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>'; | |
endwhile; | |
echo '</ul>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment