Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type with several taxonomies within it

Eg. the post type is called campsites and the taxonomies are various counties: cheshire, staffordshire etc.

What I want to do is: list all of the counties and when you click on a county it links through to a page which lists all of the posts within that County. How can I do that.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

There are plenty of functions for grabbing the data you need, a quick look at the Codex function reference reveals many useful functions you can use to build this.

Use get_term_link to get the link to that terms archive, and wp_get_object_terms to get the terms of an object/post.

To get all terms in a taxonomy use get_terms

You'll find examples on each function page, e.g. displaying all terms in a taxonomy and linking to them:

$args = array( 'taxonomy' => 'my_term' );

$terms = get_terms('my_term', $args);

$count = count($terms); $i=0;
if ($count > 0) {
    $cape_list = '<p class="my_term-archive">';
    foreach ($terms as $term) {
        $i++;
        $term_list .= '<a href="/term-base/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';
        if ($count != $i) $term_list .= ' &middot; '; else $term_list .= '</p>';
    }
    echo $term_list;
}

Though that example could be improved greatly by replacing the hyperlink code with code that uses get_term_link.

There are other useful functions such as wp_list_categories but that function is not as flexible and limits you to a dropdown box or list rather than whatever arbitrary markup you'd prefer

share|improve this answer
1  
Thank you so much! –  Chris Nov 19 '12 at 14:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.