On the site that I am working on I have Jobs as a custom post type and Locations as custom taxonomy. The Locations are used by Jobs, Posts, and other CPTs.
I am working on a small filter for the jobs and want to show a list of all Locations as links that after you click on one it will sort the page to show only Jobs at that location. Using simple link queries.
I am using get_categories() to generate the list of locations, but the problem with that function is that will not allow me to specify Post Type and shows all locations that have any type of post. So I end up with a list of locations that not all have jobs and when click on the link it will show an 404 page.
<?php
$args = array(
'type' => 'post', //changing this to jobs does not have any effect...
'child_of' => 0,
'parent' => 0,
'orderby' => 'count',
'order' => 'DESC',
'hide_empty' => 1,
'hierarchical' => 0,
'exclude' => '',
'include' => '',
'number' => '9999',
'taxonomy' => 'location',
'depth' => 0,
'pad_counts' => true);
$categories = get_categories($args);
$checked = false;
foreach($categories as $category) {
echo '<li><a href="/jobs/?location='.$category->slug.'">'.$category->name.'</a></li>';
}
?>
How to tell get_categories() to show only post_type => Jobs? Is there another way to show a list of locations and hide the ones that do not have jobs in them?
Thanks in advance!