Skip to content

Instantly share code, notes, and snippets.

@gyrus
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyrus/e3f40bd299e93f7282ff to your computer and use it in GitHub Desktop.
Save gyrus/e3f40bd299e93f7282ff to your computer and use it in GitHub Desktop.
Allows the artificial multiplication of posts in WordPress queries for testing purposes.
<?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