Here's my problem:

I have a Custom Post Type called Projects. In it's archive (archive-projects.php) I display a list of Clients (it's a custom taxonomy for this Projects).

This works great, you can see the clients and then click on it to see the projects related to that client.

The only issue is the pagination. In this archive-projects.php the pagination takes in consideration the number of projects but I'm actually only displaying the clients (taxonomy).

e.g: I have 10 clients (should be 1 page) but since I have 20 projects it shows 2 pages.

Is there any way to tell the pagination to use the data from the taxonomy get_terms query?

Here's my code:


        $args = array(
            'posts_per_page'   => 9,
            'paged' => get_query_var('paged'),
            'orderby'          => 'name',
            'order'            => 'ASC',
            'post_type'        => 'projects',
            'post_status'      => 'publish'

        $clientes = get_terms( 'cliente', $args );

     foreach ( $clientes as $cliente ) :             

                $args = array(
                     'posts_per_page' => 1,
                     'orderby' => 'ID',
                     'order'   => 'DESC',
                      'post_type' => 'projects',
                    'tax_query' => array(
                                'taxonomy' => 'cliente',
                                'field' => 'slug',
                                'terms' => $cliente->slug
                     'post_status' => 'publish'
                $projects = get_posts( $args );

                foreach ( $projects as $post ) : setup_postdata( $post ); 

                    // Here we print the last proyect from this client

                endforeach; // END $projects foreach


       endforeach; // END $clientes foreach

  • I think you can use the archive for the taxonomy instead of the archive for custom post type. In this way loop and pagination are related to terms (clients), not to post (projects). Then in this loop you can query for projects. However it isn't really efficient. Probably it'll be better to use a custom query to group the projects by taxonomy, something like this Jan 24, 2014 at 12:11
  • Thanks for the tip Lucio, I'll check out the custom query. The reason I use the projects archive is because of the URL. We want to use domain.com/projects to display the clients (I know.. I know...). If we use the client slug (singular) it won't make much sense to have a list of clients under: domain.com/client
    – Ricard
    Jan 24, 2014 at 12:18
  • 1
    Ok :) Consider that you can set the rewrite slug for a custom taxonomy, check it on the Codex. So you can use domain.com/projects for the taxonomy 'clients'. But remember to change the slug for 'projects' to something else! Jan 24, 2014 at 12:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.