Last active
August 29, 2015 14:04
-
-
Save gyrus/e3f40bd299e93f7282ff to your computer and use it in GitHub Desktop.
Allows the artificial multiplication of posts in WordPress queries for testing purposes.
This file contains hidden or 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 | |
/** | |
* Allow the multiplication of posts in query results for testing purposes. | |
* | |
* In the query args, set pilau_multiply to the number you want the posts multiplying by. | |
* NOTE: If using get_posts() instead of WP_Query, you will need to set suppress_filters to true. | |
*/ | |
add_filter( 'the_posts', 'pilau_multiply_posts', 10, 2 ); | |
function pilau_multiply_posts( $posts, $query ) { | |
// Is the query set to multiply | |
if ( isset( $query->query['pilau_multiply'] ) && $query->query['pilau_multiply'] ) { | |
// Store original set of posts | |
$posts_original = $posts; | |
// Multiply | |
for ( $i = 1; $i < $query->query['pilau_multiply']; $i++ ) { | |
$posts = array_merge( $posts, $posts_original ); | |
} | |
// Adjust count | |
$query->found_posts = count( $posts ); | |
} | |
return $posts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment