• Hi I need some help.

    I’ve made a custom post type for classes, all the custom post values are inserted into a table, I need the classes to be separated by day, while all being in the same table.

    I’ve made a taxonomy for the post type call day, I would like all posts with the Monday taxonomy to be displayed under a Monday heading.

    I’m not sure how to do this, I was thinking of using multiple loops but I can’t even get one day to display on it’s own.

    Please help.

Viewing 1 replies (of 1 total)
  • Here is some sample code that should do what you want. The display is crude, so you will need to rework it for your needs.

    $post_type = 'classes';
    $taxonomy = 'day';
    
    function mam_posts_fields ($fields) {
       global $mam_global_fields;
       // Make sure there is a leading comma
       if ($mam_global_fields) $fields .= (preg_match('/^\s*,/',$mam_global_fields)) ? $mam_global_fields : ", $mam_global_fields";
       return $fields;
    }
    function mam_posts_join ($join) {
       global $mam_global_join;
       if ($mam_global_join) $join .= " $mam_global_join";
       return $join;
    }
    function mam_posts_where ($where) {
       global $mam_global_where;
       if ($mam_global_where) $where .= " $mam_global_where";
       return $where;
    }
    function mam_posts_orderby ($orderby) {
       global $mam_global_orderby;
       if ($mam_global_orderby) $orderby = $mam_global_orderby;
       return $orderby;
    }
    add_filter('posts_fields','mam_posts_fields');
    add_filter('posts_join','mam_posts_join');
    add_filter('posts_where','mam_posts_where');
    add_filter('posts_orderby','mam_posts_orderby');
    
    if (!$paged = get_query_var('paged')) {
       if (!$paged = get_query_var('page')) {
          $paged = 1;
       }
    }
    $mam_global_fields = ', t.name';
    $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)
         JOIN $wpdb->terms t ON (tt.term_id = t.term_id)";
    $mam_global_where = " AND tt.taxonomy = '$taxonomy'";
    $mam_global_orderby = "t.name, $wpdb->posts.post_date DESC";
    $args = array(
       'paged' => $paged,
       'post_type' => $post_type,
       );
     query_posts($args);
     // Turn off the filters
     $mam_global_fields = $mam_global_join = $mam_global_where =
          $mam_global_orderby = '';
     if ( have_posts() ) {
       while ( have_posts() ) {
          the_post();
          if ($post->name != $curr_name) {
             echo "<br /><h2>$post->name</h2>";
             $curr_name = $post->name;
          }
          the_title();echo " = $post->name <br />";
       }
     }
Viewing 1 replies (of 1 total)
  • The topic ‘Sorting custom post types by taxonomy’ is closed to new replies.