function __call($name, $args) { switch (TRUE) { case in_array($name, self::$new_wp_query): // wp_query builder switch (count($args)) { case 2: list($query, $backups) = $args; break; case 1: default: list($query) = $args; break; } if (in_array($name, self::$new_custom_wp_query)) { $wp_query = NULL; } else { global $wp_query; } $wp_query = new WP_Query($query); while (!have_posts() and !@empty($backups)) { $wp_query = new WP_Query($backups[0]); unset($backups[0]); } if (in_array($name, self::$new_custom_wp_query)) { $this->my_wp_query = $wp_query; } // _log('trace', 'new query created'); break; case $name == 'start_query_custom': $this->wp_query->in_the_loop = TRUE; $this->cache['temp_wp_query'] = $this->wp_query; // save $this->wp_query = $this->my_wp_query; // change break; case $name == 'end_query_custom': $this->wp_query = $this->cache['temp_wp_query']; // revert $this->wp_query->in_the_loop = FALSE; array_pop($this->cache['my_wp_queries']); // delete break; case in_array($name, self::$new_page_wp_query): if (WPHF::element(0, $args) == FALSE) { return; } else { $pagename = $args[0]; } $custom_query_params = WPHF::custom_else_default(WPHF::element(1, $args), array()); $query_params = array_merge(compact('pagename') + array('showposts' => 1, 'post_type' => 'page'), $custom_query_params); $query_function = WPHF::custom_else_default(WPHF::element(2, $args), 'query'); $this->{$query_function}($query_params); if (have_posts()) { the_post(); return TRUE; } else { trigger_error('Page not found.', E_USER_NOTICE); return FALSE; } break; } }