• Resolved needtakehave

    (@needtakehave)


    I was wondering if someone could help me figure out what I am doing wrong. I’m trying to create a pagination loop for custom post types to include post (if possible) along with my custom post types. I’ve tried it without post, with JUST post, with JUST a custom post type, and still nothing.

    <?php if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); } else if ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); } else { $paged = 1; }
    	$my_query = new WP_Query( array (
    		'post_type'           => 'reviews',
    		'posts_per_page'      => 10,
    		'paged'               => $paged, ) );
    	while ( $my_query->have_posts() ) : $my_query->the_post(); ?>

    I actually did get it working now, where it works if it’s just “reviews”. However, if I edit the post_type field to;

    'post_type' => 'reviews', 'blogtours',

    Then it stops working altogether which I’m sure is because I need to have it as something else, some sort of extra array so it picks up multiple post_types at once? I’m just not good at arrays. I’m usually okay with coding as a rule but arrays is one area that always throws me (plus my current situation personally has made my brain mush so even the little things are hard lately, lol).

    Any/all help would be MOST appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Change it to the following:

    'post_type' => array( 'reviews', 'blogtours' ),
    

    I know you said they throw you for a loop, but often with WordPress, if you need to pass multiple values for something, an array is the right way to go.

    Thread Starter needtakehave

    (@needtakehave)

    Thank you! That worked! Although, I think I must have done something wrong with my older/next post part. I read that you had to edit that part too?

    This is what I have now;

    <div class="next_prev left"><?php printf ( '<div>%s</div>', get_previous_posts_link ( 'Previous Page &raquo;', $my_query->max_num_pages ) ); ?></div>
    <div class="next_prev right"><?php printf ( '<div>%s</div>', get_next_posts_link ('Next Page &raquo;', $my_query->max_num_pages ) ); ?></div>

    Which gives me the next link for ‘…./page/2/’ which I guess is correct, actually except that it gives me a 404 error so that it might not be correct for my site. So again, here, I’m not sure what I’m doing wrong.

    The original (index) php was;

    <div class="next_prev left"><?php previous_posts_link(__('&laquo; Previous Page', 'designcrumbs')); ?></div>
    <div class="next_prev right"><?php next_posts_link(__('Next Page &raquo;', 'designcrumbs')); ?></div>

    Which came with the theme…

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Main thing I’d do is make sure the WP_Query object variable matches but my hunch is that it does based on original post. Otherwise only guess I have is not enough posts for two pages or permalinks need flushed

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination’ is closed to new replies.