Skip to content

Instantly share code, notes, and snippets.

@ravismakwana
Last active January 19, 2022 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravismakwana/6bc3ebec4937a61f3275447b225b1e89 to your computer and use it in GitHub Desktop.
Save ravismakwana/6bc3ebec4937a61f3275447b225b1e89 to your computer and use it in GitHub Desktop.
List Custom Posts with Custom Taxonomy
<?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