WordPress.org

Ready to get started?Download WordPress

Forums

Custom post types & taxonomies (2 posts)

  1. ashbryant
    Member
    Posted 4 years ago #

    Hi, I need some help with WP3.0

    I'm trying to take advantage of WP3.0's new custom post types & taxonomies to create a food menu.

    So I have created the custom post type & the taxonomies I will need.
    In its basic form, there is a custom post type of "Dishes", which has a title, some text & a couple of taxonomies "Price" & "Dish Type".

    From this, I can give the Dish a name a price & say if it is a main course or a starter etc.

    So far so good.

    But the trouble I'm having is finding any documentaion on how I can get that date to be shown on a template.

    I have got this far...

    <ul>
    <?php global $wp_query;
    $wp_query = new WP_Query("post_type=dishes&post_status=publish");
    
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    This will list out the custom post, but I need more control of the dishes it lists. I need to list our first the starters, then the mains and so on.

    Also how do I go to the next step of having it also list the prices along with the titles?

    After that what changes do you need to make in order to get a single custom post to be displayed??

    Nightmare!

    Can anyone help?

    please.

    Thanks

  2. MichaelH
    Member
    Posted 4 years ago #

    It would seem you could also do this without resorting to custom post types or taxonomies, but that's another topic, right ;)

    I need to list our first the starters, then the mains and so on.

    <?php
    $post_type = 'dishes';
    $tax = 'dish_type';
    $tax_terms = get_terms($tax);
    if ($tax_terms) {
      foreach ($tax_terms  as $tax_term) {
        $args=array(
          'post_type' => $post_type,
          "$tax" => $tax_term->slug,
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
        );
    
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of '.$post_type . ' where the taxonomy '. $tax . '  is '. $tax_term->name;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <?php
            echo get_the_term_list( $my_query->post->ID, 'price', 'Price: ', ', ', '' );
            echo get_the_term_list( $my_query->post->ID, 'dish_type', 'Dish Type: ', ', ', '' );
          endwhile;
        }
        wp_reset_query();
      }
    }
    ?>

    Also how do I go to the next step of having it also list the prices along with the titles?

    For each of dishes, when displaying them in that loop you can use this to display the price and dish_type:

    echo get_the_term_list( $post->ID, 'price', 'Price: ', ', ', '' );
    echo get_the_term_list( $post->ID, 'dish_type', 'Dish Type: ', ', ', '' );

    After that what changes do you need to make in order to get a single custom post to be displayed??

    You mean something more than the single dish display that would be presented if the visitor clicks on the dish title you displayed?

Topic Closed

This topic has been closed to new replies.

About this Topic