Return to Snippet

Revision: 46037
at May 12, 2011 01:09 by pmalerba


Initial Code
$mf_query = <<<EOF
    SELECT t.*, tt.*, p.*
    FROM {$wpdb->posts} as p, {$wpdb->term_relationships} as tr, {$wpdb->terms} AS t, {$wpdb->term_taxonomy} AS tt
    WHERE tt.`taxonomy` = 'bodies-of-work'
    AND t.`term_id` = tt.`term_id`
    AND tr.`object_id` = p.`ID`
    and tt.`term_taxonomy_id` = tr.`term_taxonomy_id`
    AND tt.`count` > 0
    GROUP BY t.`term_id`
    ORDER BY p.`post_date` DESC 
EOF;

$mf_terms = $wpdb->get_results( $mf_query );

if( !empty( $mf_terms ) ) {
    print "\n\t" . '<ul>';
    foreach ( $mf_terms as $mf_term ) {
        print "\n\t\t" . '<li><a href="' . get_term_link( $mf_term, $mf_term->taxonomy ) . '">' . $mf_term->name . '</a></li>';
    }
    print "\n\t" . '</ul>';
} 

Initial URL


Initial Description


Initial Title
Wordpress query term taxonomy

Initial Tags
wordpress, query

Initial Language
PHP