WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to order different custom post type in category or tag template page? (6 posts)

  1. johnfrancisco
    Member
    Posted 2 years ago #

    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

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    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?

  3. johnfrancisco
    Member
    Posted 2 years ago #

    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…

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    Remove the code you have in your functions.php and use something like this example: http://pastebin.com/MvnWk3PA

    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

  5. johnfrancisco
    Member
    Posted 2 years ago #

    Done.
    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.

  6. keesiemeijer
    moderator
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic