Skip to content

Instantly share code, notes, and snippets.

@qwersk
Created June 28, 2017 09:17
Show Gist options
  • Select an option

  • Save qwersk/0293fd7e128912ab3246ef48145eb923 to your computer and use it in GitHub Desktop.

Select an option

Save qwersk/0293fd7e128912ab3246ef48145eb923 to your computer and use it in GitHub Desktop.
PAGINATION IN SINGLE.PHP #WORDPRESS #WP
add_action( 'template_redirect', function() {
if ( is_singular( 'authors' ) ) {
global $wp_query;
$page = ( int ) $wp_query->get( 'page' );
if ( $page > 1 ) {
// convert 'page' to 'paged'
$query->set( 'page', 1 );
$query->set( 'paged', $page );
}
// prevent redirect
remove_action( 'template_redirect', 'redirect_canonical' );
}
}, 0 ); // on priority 0 to remove 'redirect_canonical' added with priority 10
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 2,
'post_type' => 'course',
'paged' => $paged,
'page' => $paged
// 'meta_query' => array(
// array(
// 'key' => 'direction', // name of custom field
// 'value' => '"' . $direction_id . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
// 'compare' => 'LIKE'
// )
// )
);
query_posts($args); if (have_posts()) : while (have_posts()) : the_post();
echo paginate_links( array(
'total' => 3,
'show_all' => true
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment