Support » Fixing WordPress » Custom Post Type and Taxonomies: getting slug?

  • I’m doing a site for a wine importer.

    I’ve set up two custom post types: WINES and VINEYARDS.
    The wines have a taxonomy of WINERY, which corresponds to the VINEYARDS post type.

    So I want the VINEYARDS page to have a list of wines they produce, pulled from the taxonomy WINERY.

    Here’s the code that does that (except for the problem line: “VINEYARD-NAME-HERE” SHOULD be the slug):

    $args = array(
        'post_type' => 'wines',
        'winery' => 'VINEYARD-NAME-HERE'
     $lastposts = get_posts($args);
     foreach($lastposts as $post) :
     <li><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>

    That works fine except of course, I’m hand-coding the “vineyard-name” slug and building a new page template for each vineyard. Address of the vineyard page is like this:

    I’m sure there’s an easier way. Care to help?

    I’ve set up post types and taxonomies with the Custom Post Types UI Plugin, if that makes any difference.

    Thanks in advance.

  • The topic ‘Custom Post Type and Taxonomies: getting slug?’ is closed to new replies.