0
votes

ok, here's what I'm trying to do:

I've got a custom post type called drinks-menu, a taxonomy called drinks-menu-categories, and a page template called template-drinks-menu.php.

The taxonomy has a bunch of terms that are heirarchical - Wine, with children White and Red; Beer, with children Pilsener, Stout, etc...

I want to use one loop to display all the posts from these terms in the same order that they're ordered by in the admin. Here's the code I've got so far:

    <?php

    $post_type = 'drinks-menu';

    // Get all the taxonomies for this post type
    $taxonomies = get_object_taxonomies( (object) array('post_type' => $post_type ) );

    foreach( $taxonomies as $taxonomy ) : 

        // Gets every "category" (term) in this taxonomy to get the respective posts
        $terms = get_terms( $taxonomy );

        foreach( $terms as $term ) : 

            echo '<h1>'.$term->name.'</h1>';
            if ( $term->description !== '' ) { 
                echo '<div class="page_summary">'. $term->description .'</div>';
            }
            echo '<br>';

            $posts = new WP_Query( "taxonomy=$taxonomy&term=$term->slug&posts_per_page=-1&orderby=id&order=DESC" );

            if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();

                ?>
                <a href="<?php the_permalink(); ?> "><?php the_title(); ?></a>
                <?php
                if( get_field( "price" ) ): ?>
                    <?php echo '<span">'; the_field( "price" ); echo ' | '; the_field( "abv" ); echo '</span>';?>
                <?php endif;
                echo '<em>'; the_excerpt(); echo '</em><br><br>';

            endwhile; endif;

        endforeach;

    endforeach;

    ?>

This is working well to bring all the posts from the terms onto the page, but not in order. You can see I tried taxonomy=$taxonomy&term=$term-slug&posts_per_page=-1&orderby=id&order=DESC but it's not working, everything shows in alphabetical order.

Any Wordpress gurus who can point me in the right direction? I hope I've been clear about the issue. Thanks :-)

1
In which order you want post?Bindiya Patoliya
post order or term order ?M Khalid Junaid
Post order, the way they're ordered in the admin. By ID, I'm thinking? But that's what I tried and it didn't do that. I don't want the terms to be alphabetical.Jonathan

1 Answers

0
votes
  1. Posts ordered in admin page by "menu_order";
  2. If u want to order posts using query_posts (WP_Query constructor) u should use value of variable "orderby" in upper case -> "ID".