Support » Fixing WordPress » How to order different custom post type in category or tag template page?

  • Resolved johnfrancisco


    I have 3 differents custom post type : “Projet”, “Notice” and “Disque”. I want them to appear in a specific order when they are listed in the category or the tag template page. Like that :

    1 – Notice

    2 – Projet

    3 – Disque

    I’ve tried to catch te query string and use 3 different loops with WP_Query with no results.

    <?php $my_notices_query = new WP_Query($query_string.'&post_type=notices&posts_per_page=1'); // only notices… ?>
    <?php while ($my_notices_query->have_posts()) : $my_notices_query->the_post(); ?>

    The query allways show all the cpt with no restriction.
    My solution is not working because it is just not filtering the custom post type as I want. To keep getting the wanted tag or category of the initial query, I must keep the $query_string in the new query… I think the better solution would be to filter and order that in functions.php but I don’t know how.
    And I must say that I already add this code to make appear the cpt in my tag and category template page.
    Thks for your help. BR

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer


    I think the only way you can order by post_type is with multiple loops. Unfortunately pagination will only work with a single loop. Do you need pagination with this?

    No I don’t care pagination.
    But as I say, my problem is not about multiple loop (I can handle that…), it’s more about correctly filtering the wanted cpt in the 3 querys…

    Moderator keesiemeijer


    Remove the code you have in your functions.php and use something like this example:

    This simplified example shows two loops that get the latest post from the post types ‘post’ and ‘book’ and only shows the title. You have to adjust it to your own loops and post types

    Thks it works perfectly well.
    As you say, I have removed the filter code in functions.php and the WP_query loops work perfectly well, as I want.
    No more pagination but for this, it’s not important.
    Thanks keesiemeijer.

    Moderator keesiemeijer


    You’re welcome. I’m glad you got it resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to order different custom post type in category or tag template page?’ is closed to new replies.