for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Classy;
class Query_Helper {
/**
* Finds or creates new query based on provided params
*
* @param array|boolean $args
* @return object WP_Query
*/
public static function find_query( $args = false ) {
$default_args = array();
if ( ! $args ) {
return self::get_current_query();
} elseif ( is_array( $args ) ) {
$args = array_merge( $default_args, $args );
$args
return new \WP_Query( $args );
} else {
return new \WP_Query( $default_args );
}
* Returns current WP_Query
public static function get_current_query() {
global $wp_query;
global
Instead of relying on global state, we recommend one of these alternatives:
function myFunction($a, $b) { // Do something }
class MyClass { private $a; private $b; public function __construct($a, $b) { $this->a = $a; $this->b = $b; } public function myFunction() { // Do something } }
$query =& $wp_query;
$query = self::handle_maybe_custom_posts_page( $query );
return $query;
* Checks and returns WP_Query for home posts page
* @param object $query WP_Query
private static function handle_maybe_custom_posts_page( $query ) {
if ( $custom_posts_page = get_option( 'page_for_posts' ) ) {
if ( isset( $query->query['p'] ) && absint( $query->query['p'] ) === absint( $custom_posts_page ) ) {
return new \WP_Query( array( 'post_type' => 'post' ) );