WordPress.org

Forums

custom post types, taxonomies -trying to display all posts in current category (10 posts)

  1. isaachorton
    Member
    Posted 4 years ago #

    Im having the hardest time trying to figure this out.

    Im just trying to create a list of all the "custom post type" posts belonging to the current category linked to "custom post type" post.

    Its the custom post types that's really throwin me for a loop.

  2. jevets
    Member
    Posted 4 years ago #

    Jonathan Christopher just wrote two thorough tutorials on working with custom post types and custom taxonomies. These will probably help you.

    http://mondaybynoon.com/2010/09/06/custom-post-types-taxonomies-permalinks-wordpress/
    http://mondaybynoon.com/2010/09/06/wordpress-archive-pages-taxonomy/

  3. isaachorton
    Member
    Posted 4 years ago #

    I cant find the code to simply list all the (custom-post-type)titles with links in a particular custom taxonomy.

    For instance, I want to have a list of associated posts in a particular category but the category is a custom taxonomy and the posts are a custom post type. What would be the code to list just titles with links from the associated category?

    Also, is there a way to define the current category in a custom taxonomy? Let’s pretend that there is always only one category in each taxonomy associated with each post. I want to define the current category within a defined custom taxonomy… then list all it's contents. Is there a way to do that?

    These custom posts/taxonomies have me scratching my head a bit…. lol!

  4. isaachorton
    Member
    Posted 4 years ago #

    i was thinking of modifying this bit... any suggestions?

    // Get the selected terms for the post (if has more than one use the first)
    $term = wp_get_object_terms($post->ID, 'Filters');
    
    if ( $term ) { $term = $term[0]; }
    
    //now you can use $term->slug, $term->name, $term->term_id, etc
  5. isaachorton
    Member
    Posted 4 years ago #

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    
    query_posts($query_string . "&cat=".$term->term_taxonomy_id);
    ?>

    Ok so how do i edit this to display the posts in the custom taxonomy?

  6. isaachorton
    Member
    Posted 4 years ago #

    ok figured it out. wasnt displaying becuase of the php function above it in the template.

    this is solved.

  7. isaachorton
    Member
    Posted 4 years ago #

    ok i was wrong I cant get this to work anybody have a snippet of code for this?

  8. jevets
    Member
    Posted 4 years ago #

  9. isaachorton
    Member
    Posted 4 years ago #

    The code below lists out all the terms in the taxonomy, but Id like to list only the associated post-types in the CURRENT category. In this case my taxonomy is "courses" and I just want to define the current term in "courses" and list the rest of the pages accordingly.
    any clues how to accomplish this?

    <li id="brands" class="widget-container">
      <?php $cam_brands = get_terms('courses', 'hide_empty=1'); ?>
      <ul>
        <?php foreach( $cam_brands as $brand ) : ?>
          <li>
            <a href="<?php echo get_term_link( $brand->slug, 'courses' ); ?>">
              <?php echo $brand->name; ?>
            </a>
            <ul>
              <?php
                $wpq = array( 'post_type' => 'portfolio-item', 'taxonomy' => 'courses', 'term' => $brand->slug );
                $brand_posts = new WP_Query ($wpq);
              ?>
              <?php foreach( $brand_posts->posts as $post ) : ?>
                <li>
                  <a href="<?php echo get_permalink( $post->ID ); ?>">
                    <?php echo $post->post_title; ?>
                  </a>
                </li>
              <?php endforeach ?>
            </ul>
          </li>
        <?php endforeach ?>
      </ul>
    </li>
  10. ignitionmedia
    Member
    Posted 4 years ago #

    I need to do the same, isaachorton did u find a solution?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.