Support » Fixing WordPress » List of posts using custom taxonomy term

  • I have a custom taxonomy. At the bottom of each post I want to list all posts that use the same term.


    function addmylist($content){
      global $post;
      $term = get_post_term($post->ID, 'mytaxonomy');
      $extra = wp_page_list(array('include'=>get_postids_using_term($term, 'mytaxconomy')));
      return $content . $extra;

    Is there a way of actually doing this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Haven’t used this for a while but might see if you can make it fit:

    //for in the loop, display all "content", regardless of post_type,
    //that have the same custom taxonomy (e.g. genre) terms as the current post
    $backup = $post;  // backup the current object
    $found_none = '<h2>No related posts found!</h2>';
    $taxonomy = 'genre';//  e.g. post_tag, category, custom taxonomy
    $param_type = 'genre'; //  e.g. tag__in, category__in, but genre__in will NOT work
    $post_types = get_post_types( array('public' => true), 'names' );
    $tax_args=array('orderby' => 'none');
    $tags = wp_get_post_terms( $post->ID , $taxonomy, $tax_args);
    if ($tags) {
      foreach ($tags as $tag) {
          "$param_type" => $tag->slug,
          'post__not_in' => array($post->ID),
          'post_type' => $post_types,
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
            <?php $found_none = '';
    if ($found_none) {
    echo $found_none;
    $post = $backup;  // copy it back
    wp_reset_query(); // to use the original query again

    Thanks Michael. Won’t that put me in an infite loop if I put it in the ‘the_content’ filter?

    Not sure what would happen–of course that example is for use in a template such as index.php or a Page Template.

    I was hoping to pop it in a plugin, to make it theme independent.

    It seemed such a simple thing when I started it!

    Then look for Otto’s PHP Code widget plugin and use that.

    Thanks, bu that would still have theme dependence (i.e. a widgetised area)?

    I’ll have a go at going the long route via get_objects_in_term() and get_posts()

    There is nothing stopping you from putting that in a plugin. You might use a Shortcode or even filter on the_content.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘List of posts using custom taxonomy term’ is closed to new replies.