WPIntell

Source evidence

Custom post types

cbnet Different Posts Per Page · support · 2012-12-20T23:54:00+00:00

mixedsentiment
mediumseverity
0.72relevance
3replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

6 / 35 rows with source links

17.1% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

29 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
Martijnchel resolved
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/ 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 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. 🙂

Comments

3 shown
Chip Bennett 2012-12-21T00:40:00+00:00

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.

Martijnchel 2012-12-21T00:44:00+00:00

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

Chip Bennett 2012-12-21T00:49:00+00:00

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. 🙂