• Hi all,
    Sorry if this has been covered, been googling for a while.
    I have a query that contains 3 custom post types (‘news’, ‘exhibitors’, ‘speakers’).
    I would like to display a total of 6 posts per page and 2 custom post types each, so two news, two exhibitors and two speakers.
    Currently if I specify ‘posts_per_page’ => 6′ and there is only 1 news article, 1, exhibitor there will be 4 speakers shown.
    I almost need a ‘posts_per_post_type’ if that makes sense.
    Query below, many thanks in advance.

    $args = array( 'post_type' => array('news', 'exhibitors', 'speakers'), 'posts_per_page' => 6, 'order' => 'DESC', 'orderby' => 'type',  'paged' => $paged, 'tax_query' => array(
                            array(
                                'taxonomy' => 'foebar',
                                'field' => 'slug',
                                'terms' => array( $post_slug ) 
                            )
                        ));
    • This topic was modified 5 years, 9 months ago by Ainsley Clark.
Viewing 2 replies - 61 through 62 (of 62 total)
  • Thread Starter Ainsley Clark

    (@ainsleyclark)

    Hi @vrandom

    Thanks for your reply, sorry about the long delay. Thank you for being so patient.

    I have deduced that it was down to me being clumsy and not changing my category on this line.

    where foe_342fj29x2_term_taxonomy.taxonomy = 'foebar' and foe_342fj29x2_terms.slug = '$post_slug'

    Its working ??

    The only issue I have is with it returning an extra page. As In, I click the ‘next page’ on the last one and it displays no posts.

    Would there be a way to fix this?

    Many many thanks.

    Hi @ainsleyclark

    Awesome glad it started working mostly – lol.

    Not sure what could be causing the page number problem.

    I guess start dumping out the vars and checking the math.

    
    // set vars for found_posts, max_posts_count and build the post_order_index
    $found_posts = 0;
    $max_posts_count=0;
    foreach ($page_count_per_post_type as $page_count) {
    
    	// make a total post found for all post_types
    	$found_posts += $page_count[0];
    
    	// max posts - total of posts per type
    	$max_posts_count += $page_count[0];
    
    	// set up post order index
    	$post_order_index[$page_count[1]] = explode(',', $page_count[2]);
    
    }
    
    // set the max pages for the results
    $max_posts_num_pages = ceil( $max_posts_count / ($post_per_posttype * count($post_types)));
    
Viewing 2 replies - 61 through 62 (of 62 total)
  • The topic ‘Posts Per Page -> Per Post Type’ is closed to new replies.