Last active
January 19, 2023 01:15
-
-
Save yankiara/4d9e6c1770897048a6072e85b058e0e9 to your computer and use it in GitHub Desktop.
Allow Wordpress posts pagination on frontpage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Put following code BEFORE running the query (WP loop, Oxygen's repeater, etc.) | |
* What it does: | |
* - updates query with right page number variable to display the correct page | |
* - assigns the query to wp_query so that pagination links work | |
*/ | |
function handle_pagination_on_frontpage( $query ) { | |
global $wp_query; | |
if ( !is_admin() && is_front_page() && $query->query['post_type'][0] == 'YOUR_POST_TYPE' ) { | |
$paged = get_query_var( 'page' ); | |
$query->set( 'paged', $paged ? $paged : 1 ); | |
$wp_query = $query; | |
} | |
} | |
add_action( 'pre_get_posts', 'handle_pagination_on_frontpage' ); | |
/* | |
* Put following code AFTER the query | |
*/ | |
remove_action( 'pre_get_posts', 'handle_pagination_on_frontpage' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment