WordPress.org

Ready to get started?Download WordPress

Forums

WP-PageNavi
help paginating custom archive posts query by category (5 posts)

  1. studioleland
    Member
    Posted 3 years ago #

    Having a lot of trouble getting pagination to work for the following query which queries all posts(custom post type) of custom taxonomy and displays them in columns. The output is perfectly handled except I have been unable to accomplish any kind of paginating. Hopefully someone can shed some light.

    $post_type = 'retailers';
    					$tax = 'states';
    					$tax_terms = get_terms($tax);
    					$post_counter = 0; // reset so we can generate columns
    					$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    					if ($tax_terms) { ?>
    
    					  <ul class="column_wrap" style="margin:0 10px; padding:0; width:150px; float:left;">
    
    					  <?php foreach ($tax_terms as $tax_term) {
    						$args=array(
    						  'post_type' => $post_type,
    						  "$tax" => $tax_term->slug,
    						  'post_status' => 'publish',
    						  //'posts_per_page' => -1,
    						  'posts_per_page' => 15,
    						  'paged' => $paged,
    						  'orderby' => 'title',
    						  'order' => 'ASC',
    						  'caller_get_posts'=> 1
    						); // END $args
    
    						$my_query = null; // clear the query variable
    						$my_query = new WP_Query($args);
    
    						if( $my_query->have_posts() ) { ?>
    
                              <li class="column_row">
    
                                <div class="retailer_state_wrap" style="width:150px; float:left; margin:0 10px;">
                                    <h4><?php echo $tax_term->name; ?></h4>
                                </div>
    
                              </li>
    
    						  <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
                              	<li class="column_row">
    
                                  <div class="retailer_wrap retailer_id-<?php the_ID(); ?>" style="margin:0 10px; padding:0; width:150px; float:left;">
                                    <p>
                                      <span class="retailer_title"><?php the_title(); ?></span><br />
                                      <span class="retailer_address">
                                        <?php if (get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0', true)) { ?>
                                          <?php echo get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0', true); ?>
                                        <?php } ?>
                                        <?php echo " "; ?>
                                        <?php if (get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0', true)) { ?>
                                          <?php echo get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0', true); ?>
                                        <?php } ?>
                                      </span><br />
                                      <span class="retailer_phone">
                                        <?php if (get_post_meta($post->ID, '_simple_fields_fieldGroupID_2_fieldID_3_numInSet_0', true)) {
                                          echo get_post_meta($post->ID, '_simple_fields_fieldGroupID_2_fieldID_3_numInSet_0', true); ?>
                                        <?php } ?>
                                      </span>
                                    </p>
                                  </div>
                                  <?php $post_counter++; ?>
                                </li>
    
                                <?php if ( 0 == $post_counter % 3 ) { ?>
            				      </ul>
                                  <ul class="column_wrap" style="margin:0 10px; padding:0; width:150px; float:left;">
    							<?php } ?>
                              <?php
    						  endwhile;
    						  wp_pagenavi( array( 'query' => $my_query ) );
    						} // END if have_posts loop
    						wp_reset_query();
    
    					  } // END foreach $tax_terms
    					} // END if $tax_terms
  2. studioleland
    Member
    Posted 3 years ago #

    Basically does this:

    if (custom tax)
    foreach (custom tax){
    print custom tax title
    if (custom post type)
    while (custom post type sorted)
    print custom post title, content, post meta.
    endwhile
    endif
    endforeach
    endif

    How can I paginate this by post number. I need it to page after every 15 posts regardless of the taxonomy loop. Any help? Right now I have:

    'posts_per_page' => 15, 'paged' => $paged,

    as args in the foreach custom tax loop

    Please see raw code above.

  3. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Not really sure how this is supposed to look. What happens if you just call wp_pagenavi()?

    Sidetopic: What's the point of the if checks:

    <?php if (get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0', true)) { ?>
      <?php echo get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0', true); ?>
    <?php } ?>

    (hint: none)

  4. studioleland
    Member
    Posted 3 years ago #

    Oh sorry, here is the current dev demo display:

    http://bottlesup-07112011.31two.com/bottlesup-retailers/

    I will probably remove the if checks. Bad habit. The above linked page actually has the wp-pagenavi code inserted but as you can see it doesn't look to be working.

  5. studioleland
    Member
    Posted 3 years ago #

    I get same result if I just call the wp-pagenavi(). Nothing changes. No paging.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic