• Resolved scarekrow76

    (@scarekrow76)


    Could anyone give me a push in the right direction? This is for a menu system.

    I currently have Posts and 2 Taxonomies. Based on the ID of a Term in the first Taxonomy, I need to return a list/array of Terms in the second Taxonomy where they share a common Post.

    Does that make sense?

Viewing 4 replies - 16 through 19 (of 19 total)
  • Thread Starter scarekrow76

    (@scarekrow76)

    Its a standalone function, so can be used in or outside of the content loop. This is how I’m using it within my functions.php file…

    $subterms = get_associated_terms( 'tasks', $term->term_id );
    
    if ( $subterms ) {
    	$item_output .= '<div><h5>' . __( 'Tasks' ) . '</h5><ul>';
    	foreach ( $subterms as $subterm ) {
    		$item_output .= '<li><a href="' . $term_link . 'tasks/' . $subterm->slug . '">' . $subterm->name . '</a></li>';
    	}
    	$item_output .= '</ul></div>';
    }

    Try removing the WHERE clause from my SQL string and print_r() the resulting Object to your page. Is it returning anything?

    @cornflower Design,

    I figured the problem! Turn out I forgot to change the $wpdb->posts.post_type = ‘post’ to the custom post type. Now it works like a charm!!!

    Thanks, You rock!

    Thread Starter scarekrow76

    (@scarekrow76)

    @wp_dummy : To maintain flexibility you could add a third parameter (defaulting to ‘post’) to the function to allow you to specify the target post type.

    get_associated_terms( $taxonomy_slug, $term_id = 0, $post_type = 'post' )

    @cornflower Design, wow…never thought of that. thank you very much . ??

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘Querying Taxonomies’ is closed to new replies.