Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salcode/b6c5eb8668e533a7c3ae2144eb2fd110 to your computer and use it in GitHub Desktop.
Save salcode/b6c5eb8668e533a7c3ae2144eb2fd110 to your computer and use it in GitHub Desktop.
<?php
/**
* Set the number of posts on the Custom Post Type archive for `fe_recipe` to 5.
*/
add_action( 'pre_get_posts', 'fe_modify_number_of_posts_per_page' );
/**
* Modify Posts Per Page for CPT `fe_recipe`
*
* @param WP_Query $query The current query about to be run.
*/
function fe_modify_number_of_posts_per_page( $query ) {
if ( ! $query->is_main_query() ) {
return;
}
if (
isset( $query->query['post_type'] )
&& 'fe_recipe' === $query->query['post_type']
) {
$query->set( 'posts_per_page', 5 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment