• Resolved Rose

    (@eos-rose)


    I am using the following code to create an index page listing all posts with the terms in a specific taxonomy:

    function list_posts_by_taxonomy( $post_type, $taxonomy, $get_terms_args = array('exclude' => array(4, 15, 17, 18, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 86, 87, 88, 89)), $wp_query_args = array() ){
        $tax_terms = get_terms( $taxonomy, $get_terms_args );
    
        if( $tax_terms ){
            foreach( $tax_terms  as $tax_term ){
                $query_args = array(
                    'post_type' => $post_type,
                    "$taxonomy" => $tax_term->slug,
                    'post_status' => 'publish',
                    'posts_per_page' => -1,
    				'orderby'=> 'name',
    				'order' => 'ASC',
                    'ignore_sticky_posts' => true
                );
                $query_args = wp_parse_args( $wp_query_args, $query_args );
    
                $my_query = new WP_Query( $query_args );
                if( $my_query->have_posts() ) {
    			?>
    
                    <h2 id="<?php echo $tax_term->slug; ?>" class="tax_term-heading"><?php echo $tax_term->name; ?></h2>
                    <ol class="taxonomy-list">
                    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
                        <li class="<?php my_post_class(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
                    <?php endwhile; ?>
                    </ol>
                    <?php
                }
                wp_reset_query();
            }
        }
    }

    I have two issues:

    (1) I wish to exclude all posts with the word “Series” in the title from inclusion in my index.

    (2) For those posts that are tagged with a term in the “series” taxonomy, I wish to display the series term’s description next to the post’s title. (If you’re curious, I’ve included a link to what is essentially each series’ table of contents in the term descriptions.)

    Advice on either of these topics would be greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Rose

    (@eos-rose)

    Obviously I was searching the wrong keywords for my first issue. I found that this will exclude the appropriate titles from the loop:

    if(strpos(get_the_title(), 'Anthology') === false) {
        // Title does not contain Anthology
    }

    If you can think of a better way to do it, I’m still open to suggestions, but for now I’m mostly concerned with how to display the term descriptions. I feel like this is probably something very obvious to people who have used term descriptions before, but I don’t even know where to start in the Codex.

    Thread Starter Rose

    (@eos-rose)

    I found the solution to my second problem as well!

    <?php $terms = get_the_terms( $post->ID , 'series' );
    if($terms) {
    	foreach( $terms as $term ) {
    		if ( $term->description !== '' )  {
    			echo '(' . $term->description . ') ';
    		}
    	}
    }
    ?>

    This will display the term description if a term description exists.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query results: exclude post w/ specific word in title display term description’ is closed to new replies.