Skip to content

Instantly share code, notes, and snippets.

@vanpariyar
Last active June 24, 2020 05:00
Show Gist options
  • Save vanpariyar/50095e7d02d181df25114e99de33dea7 to your computer and use it in GitHub Desktop.
Save vanpariyar/50095e7d02d181df25114e99de33dea7 to your computer and use it in GitHub Desktop.
Get pagination work on custom post type word press by setting the posts_per_page manually
<?php
/**
* We are hardcoding the value of the posts per page for custom post type
* Please only change if you know what you are doing.
*
* IF you found the other way you can change it.
*/
function custom_posts_per_page( $query ) {
if (!is_admin() && is_archive('newsroom') && !is_year())
$query->set( 'posts_per_page', 15 );
}
add_filter('parse_query', 'custom_posts_per_page');
/** On other example*/
function num_posts_archive_project_ie($query) {
if (!is_admin() && $query->is_archive('financials') && $query->is_main_query()) {
$query->set('posts_per_page', '-1');
}
return $query;
}
add_action( 'pre_get_posts', 'num_posts_archive_project_ie' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment