WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have
Question
i am using wp job manager plugin and i am trying to list on the frontpage only the twelve job categories according to the jobs they having. The job categories having more jobs go first. I managed to list the job categories with the above code but the problem is that the sorting and the number of categories not working as i expected. Any suggestions?
<?php echo '<ul class="job-category-list">'; ?>
<?php foreach ( get_terms( array(
'taxonomy' => 'job_listing_category',
) ) as $cat):
?>
<?php $the_query = new WP_Query( array(
'post_type' => 'job_listing',
'post_status' => 'publish',
'posts_per_page' => '12',
'orderby' => 'tag_count',
'tax_query' => array(
array(
'taxonomy' => 'job_listing_category',
'field' => 'term_id',
'terms' => $cat->term_id
)
)
) );
$count = $the_query->found_posts;
?>
<?php echo '<li><a href="'.get_term_link($cat).'" title="'.esc_attr($cat->name).'">'.$cat->name.'</a> ('.( $count ).')</li>';
?>
<?php endforeach; ?>
<?php echo '</ul>'; ?>`
0
custom-taxonomy, taxonomy, terms, wp-query
3 years
2020-03-29T12:51:26-05:00
2020-03-29T12:51:26-05:00 0 Answers
87 views
0
Leave an answer