Created
July 17, 2014 14:01
-
-
Save Clorith/c3276277e1b75c217262 to your computer and use it in GitHub Desktop.
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 | |
function set_page_for_post( $query ) { | |
/* | |
* Only run our query modifications if; | |
* This is the main query (not a custom WP_Query or similar) | |
* We are not on the admin screen | |
* It's a single post entry | |
* The post type is 'post' | |
*/ | |
if ( $query->is_main_query() & ! is_admin() && is_single() && 'post' == get_post_type() ) { | |
$page_value = isset( $_GET['random_var'] ) ? $_GET['random_var'] : false; | |
if ( ! $page_value || $page_value == 'all' || false === intval( $page_value ) ) { | |
return $query; | |
} | |
// Set the paged value for the query, and the query_vars, this is the pagination variable used by WP | |
$query->query['paged'] = $page_value; | |
$query->query_vars['paged'] = $page_value; | |
// Define this query as a paginated entry | |
$query->set( 'is_paged', true ); | |
// Return our modified query | |
return $query; | |
} | |
} | |
add_filter( 'pre_get_posts', 'set_page_for_post' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment