/** * This is the tie-into the GetPostsForm object: it returns (not prints) a form * OR it handles form submissions and returns results. * * @param array $args (optional) defines which controls should be displayed * @param string $content_tpl (optional) passed to the get_posts() function, this defines how each result will be formatted. * @return string HTML form, or HTML results if the form was property submitted. */ public static function search($args = array(), $content_tpl = null) { $Form = new GetPostsForm($args); $nonce = self::get_from_array($_POST, $Form->nonce_name); // Draw the search form if (empty($_POST)) { return $Form->generate(); } elseif (wp_verify_nonce($nonce, $Form->nonce_action)) { unset($_POST[$Form->nonce_name]); unset($_POST['_wp_http_referer']); $search_args = array(); foreach ($_POST as $k => $v) { // Strip the prefix $new_key = preg_replace('/^' . $Form->name_prefix . '/', '', $k); $search_args[$new_key] = $v; } $results = self::get_posts($search_args); if (empty($results)) { print $Form->get_no_results_msg(); } else { print $results; } } else { return "Invalid Submission."; } }