0
votes

I have 4 custom post types, say for example pt1, pt2, pt3 and pt4.

They all use the same taxonomies to categories them. On the taxonomy archive page, I would like the posts to be grouped by post-type, so any posts in pt1 appear first, then pt2, pt3 etc - at the moment they use the default ordering (which I assume is post date) so are all mixed up.

I tried to run separate queries for each post type, but this messed up the pagination. Thanks in advance!

1
You can do that by custom query. See my answer for further detailsHüseyin BABAL

1 Answers

0
votes

You can use following in archive page;

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$limit = 10;
$offset = ( $paged -1 ) * 10; 
$query = "
    SELECT $wpdb->posts.* 
    FROM $wpdb->posts, $wpdb->postmeta
    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
    ORDER BY $wpdb->posts.post_type DESC
    LIMIT $offset, $limit
 ";

 $custom_posts = $wpdb->get_results($query, OBJECT);



if ( $custom_posts ) : 
    global $post;
    foreach ($custom_posts as $post) {
        setup_postdata($post);
        the_post(); 
        get_template_part( '/partials/content-archive', get_post_format() );
    }
    the_bootstrap_content_nav(); 
endif;