Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Search within a WordPress category archive ( Genesis )
<?php
/**
*
* first function gets URL of the current page, which is used in the search as the action parameter.
* second function loads a search box above the content of a Genesis category archive.
* the category name ( slug ) is passed through a hidden input as a search query parameter.
*
**/
function current_page_url() {
$pageURL = 'http';
if( isset($_SERVER["HTTPS"]) ) {
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
add_action( 'genesis_before_content','atx_cat_search' );
function atx_cat_search() {
global $wp_query;
$my_cat = $wp_query->query_vars['category_name'];
if ( is_category() ) :
echo '
<form method="get" class="search-form" action="'. current_page_url() .'" role="search">
<input type="search" name="s" />
<input type="hidden" name="category_name" id="category_name" value="'. $my_cat .'" />
<input type="submit" value="'. __( 'Search','atx' ) .'" />
</form>
';
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.