Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Use filters to sort a query on terms of a selected taxonomy.
- // See http://wordpress.mcdspot.com/2010/05/30/filters-to-modify-a-query/
- // for the code of the filters used.
- $taxonomy = 'madeof';
- $mam_global_join = "JOIN $wpdb->term_relationships tr ON ($wpdb->posts.ID = tr.object_id)
- JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = '$taxonomy')
- JOIN $wpdb->terms t ON (tt.term_id = t.term_id)";
- $mam_global_fields = ", t.name AS term_name";
- $mam_global_orderby = "term_name ASC, $wpdb->posts.post_title ASC";
- $args = array(
- 'ignore_sticky_posts' => 1,
- 'post_type' => 'post',
- );
- $q = new WP_Query($args);
- $mam_global_join = $mam_global_fields = $mam_global_orderby = ''; // Turn off filters
- //print_r('<p>REQUEST:');print_r($q->request);print_r('</p>');
- //print_r('<p>POSTS:');print_r($q->posts);print_r('</p>');
- if ($q->have_posts()) {
- $current_term = '';
- while ($q->have_posts()) {
- $q->the_post();
- if ($current_term != $post->term_name) {
- $current_term = $post->term_name;
- echo "<h2>TERM: $current_term</h2>";
- }
- echo "<p>TERM:$post->term_name $post->post_title</p>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement