35 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
JustinCarroll
says

I have a custom post type called “portfolio” with a custom taxonomy called “portfolio-category”. Here’s the taxonomy-portfolio-category.php code:

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
if (have_posts()) : while ( have_posts() ) : the_post();
    // output
endwhile; endif;

The problem is this page is bound by Settings > Reading > Blog pages show at most 5. Five works good for the style of my blog index, but for the style of my portfolio pages I need more like 24 per page. How do I override what’s in my Settings for these custom taxonomy page templates? Hope someone can help. Thanks! :)

101 posts
  • Had an item that became a weekly top seller
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 4 years
  • Has referred 100+ members
+3 more
PixelBook
says

Try using query posts

query_posts(array(‘post_type’ => ‘portfolio’, ‘posts_per_page’ => 24, ‘taxonomy’ => ‘portfolio_category’ ));

35 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
JustinCarroll
says

Thanks for the suggestion. That’s the solution I’ve seen floating around the net. Using query_posts I coded the below. This creates 3 pages as it should. Page 1 displays, but pages 2 (/page/2/) and 3 give me a “page not found”. I never seem to get further than this spot. :(

global $wp_query;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$args = array_merge( $wp_query->query, array(
    'post_type' => 'portfolio',
    'posts_per_page' => 1,
    'tax_query' => array( array(
        'taxonomy' => 'portfolio-category',
        'field' => 'slug',
        'terms' => $term,
    ) ),
) );
query_posts( $args );
169 posts I think about colours
  • Had an item that was trending
  • Had an item that became a weekly top seller
  • Located in Greece
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
SkatDesign
says

Try this:


  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  $args=array(
    'post_type' => portfolio,
    'post_status' => 'publish',
    'taxonomy’ => 'portfolio_category',
    'paged' => $paged,
    'posts_per_page' => 24,
    'caller_get_posts'=> 1
  );
  $temp = $wp_query;  // assign original query to temp variable for later use
  $wp_query = null;
  $wp_query = new WP_Query();
  $wp_query->query($args);

if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post();

...

endwhile; endif;


35 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
JustinCarroll
says

Here’s a copy of my code just to make sure we’re on the same page, but it didn’t work. So it seems like the only way to override those Reading settings for posts it create a custom query on the page.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'post_type' => portfolio,
    'post_status' => 'publish',
    'taxonomy' => 'portfolio-category',
    'paged' => $paged,
    'posts_per_page' => 2,
    'caller_get_posts'=> 1
);
$temp = $wp_query;  // assign original query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query($args);

if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post();

I’ve been working on this problem all week. I swear I’ve read every article online about this, haha! This has been by far my biggest WP challenge to date.

35 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
JustinCarroll
says

Just an update, nothing has been solved here. I’m starting to wonder if I’ve found a Wordpress bug.

461 posts Don't be a HATER!
  • Had an item that became a weekly top seller
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
+6 more
CodeElite
says

always use wp_reset_query(); after your looping code :)


if(have_posts()):
while (have_posts()): the_post();

endwhile; endif;

wp_reset_query();

Good luck

35 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
JustinCarroll
says

Nope, didn’t work. Thanks for the suggestion though.

169 posts I think about colours
  • Had an item that was trending
  • Had an item that became a weekly top seller
  • Located in Greece
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
SkatDesign
says

Hmm try this too:

delete the if statement


if($wp_query->have_posts()) : 

leave just this:

 while($wp_query->have_posts()) : $wp_query->the_post();

remove the endif from the end of the loop and paste this:


$wp_query = null; $wp_query = $temp;


35 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+4 more
JustinCarroll
says

No, that didn’t work either. :( Ok, this will be a bit long-winded, but it will provide the best possible knowledge to troubleshoot my problem. All the information in my original post is still true. I’m using the WP PageNavi plugin for pagination. This particular problem in not getting the taxonomy-portflio-category.php page to paginate is also a problem when WP PageNavi is turned off.

I’ve had a heck of a time getting pagination to work on the homepage and on a page template page, but I did get them to work. Here’s their code:

page-home.php (used as a Page template on a static front page called “Home”)

$paged = 1;
if ( get_query_var('paged') ) $paged = get_query_var('paged');
if ( get_query_var('page') ) $paged = get_query_var('page');
$i = 0;
$loop = new WP_Query( array( 'post_type' => 'portfolio', 'paged' => $paged, 'posts_per_page' => 24 ) );
while ( $loop->have_posts() ) : $loop->the_post();
// output
$i++; endwhile;
if ( function_exists( 'wp_pagenavi' ) ) {
    wp_pagenavi( array( 'query' => $loop ) );
    wp_reset_postdata();
}

Pagination works!

page-portfolio.php (used as a Page template on a Page called “Work”)

$i = 0;
$loop = new WP_Query( array( 'post_type' => 'portfolio', 'paged' => get_query_var( 'paged' ), 'posts_per_page' => 24 ) );
while ( $loop->have_posts() ) : $loop->the_post();
// output
$i++; endwhile;
if ( function_exists( 'wp_pagenavi' ) ) {
    wp_pagenavi( array( 'query' => $loop ) );
    wp_reset_postdata();
}

Pagination works!

taxonomy-portfolio-category.php (used as a way to display portfolio sections e.g. print, photography, etc.)

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
global $wp_query;
query_posts( array_merge( $wp_query->query, array( 'posts_per_page' => 2 ) ) );
if (have_posts()) : while ( have_posts() ) : the_post();
// output
endwhile; endif;        
if ( function_exists( 'wp_pagenavi' ) ) {
    wp_pagenavi();
}

The page 1 (http://site.com/portfolio/interactive/) looks great! It’s definitely only posting 2 items and it calculates the correct number of pagination pages. But when you click on page 2 or 3 or 4 the site defaults to index.php and shows “Page not found”. Pagination fails!

Womp womp. Hopefully I can resolve this soon. It’s holding up my theme development. I’ve seen A LOT of people with this same problem of pagination on custom taxonomy pages, but no solid solutions for anyone. Please help!

by
by
by
by
by
by