socrateisabot
socrateisabot

Reputation: 847

Wordpress - Oder by Taxonomie using get_post_types and custom post type

I have some Customs post types and I've created customs taxonomy for these tags.

Exemple :

Custom post type : Menu

Custom taxonomy : Reference, Price

Basically I wanna retrieve all post by Custom post type (get all Menu), but ordered by taxonomy (by Reference)

<ul>
    <?php
    $args = array(
                 'public' => true,
                 '_builtin' => false
                 );

    $output = 'objects';
    $post_types = get_post_types($args, $output);
    foreach ($post_types as $post_type) {
    ?>
    <li>
        <a href = "<?php echo $uploads['url']; ?>/Appetizers.jpg"><?php echo $post_type->label; ?></a>
        <div class = "ac_subitem">
            <span class = "ac_close"></span>
            <h2><?php echo $post_type->label; ?></h2>
            <ul>
                <?php
                $loop = new WP_Query(array('post_type' => $post_type->name));
                while ($loop->have_posts()) : $loop->the_post();
                ?>   
                <li> 
                    <?php
                    $reference = wp_get_object_terms($post->ID, 'references');
                    foreach ($references as $reference) {
                                            echo ('<span class="reference">');
                                            echo $reference->name;
                                            echo (' .</span>');
                    }

                    $price = wp_get_object_terms($post->ID, 'price');
                    foreach ($prices as $price) {
                                            echo ('<span class="price">');
                                            echo $price->name;
                                            echo ('</span>');
                    }
                endwhile;?>
                </li>
            </ul>
        </div>                                   
        <?php
    }?>
    </li>
</ul>

The output should be :

Reference 1 -- Price £5.00

Reference 2 -- Price £3.00

Reference 3 -- Price £6.00

Many Thanks

Upvotes: 0

Views: 436

Answers (1)

Hobo
Hobo

Reputation: 7611

I don't think you can do that directly using wp_query. Have a look at this post for ways of doing it with a filter.

Upvotes: 1

Related Questions