Support » Plugin: cbnet Different Posts Per Page » Custom post types

  • Resolved Martijnchel

    (@martijnchel)


    Hi,

    I managed to get the latest version of the plugin working on my websites (updated from the old version) and everything works fine. There is only one problem; i have some custom post types which need their own number of posts per page..

    In the old plugin I could add these, now I don’t see them anymore. For me this is a big problem so is there a way to add custom post types?

    http://wordpress.org/extend/plugins/cbnet-different-posts-per-page/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Chip Bennett

    (@chipbennett)

    Theme Review Admin

    Hi Martjinchel,

    Unfortunately, one of the (perhaps temporary) casualties of completely rewriting the Plugin was removing the ability to add arbitrary categories/post types/etc. I am exploring ways to re-implement that functionality, and if I find something I like, I’ll be sure to add it in again.

    In the meantime, you can add it yourself, fairly simply, with the following hook/callback (which should be placed in functions.php or in a site-specific Plugin). Assuming you have:

    CPT: ‘foo’
    Posts per page: 5
    Order: ascending

    CPT: ‘bar’
    Posts per page: 3
    Order: descending

    function martjinchel_filter_pre_get_posts( $query ) {
        if ( is_post_type_archive( 'foo' ) && $query->is_main_query() ) {
            $query->set( 'posts_per_page', '5' );
            $query->set( 'order', 'ASC' );
        }
        if ( is_post_type_archive( 'bar' ) && $query->is_main_query() ) {
            $query->set( 'posts_per_page', '3' );
            $query->set( 'order', 'DESC' );
        }
    }
    add_action( 'pre_get_posts', 'martjinchel_filter_pre_get_posts', 11 );

    This is, in fact, all the Plugin does now. Just wash, rinse, and repeat for each custom post type you need to modify. By adding priority 11, you ensure your code executes after the Plugin, so your query filters will take precedence.

    Hi Chip,

    Thanks! Will try that first thing tomorrow.
    One question though; what do I replace the part where my name is with? I don’t know much about this, so that would help 🙂

    Thanks

    Plugin Author Chip Bennett

    (@chipbennett)

    Theme Review Admin

    One question though; what do I replace the part where my name is with?

    You don’t have to change that. You can use it as-is. 🙂

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