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

    (@chipbennett)

    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.

    Thread Starter Martijnchel

    (@martijnchel)

    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)

    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.