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
+3 more
JustinCarroll says

I’ve made some headway! There’s still an issue, but here’s the code that currently works …

function my_modify_posts_per_page() {
    add_filter( 'option_posts_per_page', 'my_option_posts_per_page' );
}
function my_option_posts_per_page( $value ) {
    return 2;
}
add_action( 'init', 'my_modify_posts_per_page', 0);

The problem is this makes ALL loops return only 2 posts per page. Right now I’m working on getting a conditional statement in there that only checks for taxonomy “portfolio-category”. I’ll let you know when I’ve finally figured this out.

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
+3 more
JustinCarroll says

Ok, I’ve done it. There must be a more graceful way to do this, but I’ve put this code in my functions.php file and it works …

$option_posts_per_page = get_option( 'posts_per_page' );
add_action( 'init', 'my_modify_posts_per_page', 0);
function my_modify_posts_per_page() {
    add_filter( 'option_posts_per_page', 'my_option_posts_per_page' );
}
function my_option_posts_per_page( $value ) {
    global $option_posts_per_page;
    if ( is_tax( 'portfolio-category') ) {
        return 2;
    } else {
        return $option_posts_per_page;
    }
}

If anyone knows a better way to write this code please hook me up! Thanks. :)

51 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+2 more
Authentic says

I couldn’t really find another way to do this. This solution worked perfectly for me. Thanks!

1 post
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
awshout says

I know this is an old thread, but I was looking for a solution to “posts_per_page” in taxonomy templates and never did find an answer. I finally figured out something that worked for me.

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

query_posts( array( 'post_type'=>'portfolio', 'portfolio-category' => $term->name, 'posts_per_page'=>20, 'paged'=>$paged ) );

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

Where ‘post_type’ is the custom post type and ‘portfolio-category’ is the custom taxonomy. I’ve tried to do this WP_query and it doesn’t work. I hope this is useful for someone else

1 post
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
slisurat says

May be you need to enable search to enable pagination

While declaring custom taxonomy you should disable search excluding.

exclude_from_search => false

This fixed my problem. I have very hard time to find this solution. Hope this helps everyone.

My code is: register_post_type( 'lifestyle', array( 'label' => __('Lifestyle', 'tmi'), 'public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'rewrite' => true, 'hierarchical' => true, 'menu_position' => 5, 'exclude_from_search' =>false, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'revisions') ) ); register_taxonomy('lifestylecat', __('lifestyle', 'tmi'),array('hierarchical' => true, 'label' => __('Categories', 'tmi'), 'singular_name' => __('Category', 'tmi')) );
by
by
by
by
by
by