07/21/2014 at 1:50 pm
#297671
Keymaster
@ Michael
I know it’s been a few days, but I think I have a solution for you to try. Install the Code Snippets plugin. Add a new snippet with the following code:
add_action( 'wp', 'cn_search_category_reset' );
function cn_search_category_reset() {
global $wp_rewrite, $post;
$keywords = get_query_var( 'cn-s' );
$categoryIDs = get_query_var( 'cn-cat' );
$categorySlug = get_query_var( 'cn-cat-slug' );
if ( ! empty( $keywords ) && ( ! empty( $categoryIDs ) || ! empty( $categorySlug ) ) ) {
cnSEO::doFilterPermalink( FALSE );
// Get the directory home page ID.
$homeID = cnSettingsAPI::get( 'connections', 'connections_home_page', 'page_id' );
$permalink = $wp_rewrite->using_permalinks() ? trailingslashit( get_permalink( $homeID ) ) : get_permalink( $homeID );
wp_redirect( add_query_arg( array( 'cn-s' => $keywords, 'cn-cat' => FALSE, 'cn-cat-slug' => FALSE ), $permalink ) );
exit;
} elseif ( ! empty( $categoryIDs ) && ! empty( $categorySlug ) ) {
cnSEO::doFilterPermalink( FALSE );
// Get the directory home page ID.
$homeID = cnSettingsAPI::get( 'connections', 'connections_home_page', 'page_id' );
$permalink = $wp_rewrite->using_permalinks() ? trailingslashit( get_permalink( $homeID ) ) : get_permalink( $homeID );
wp_redirect( add_query_arg( array( 'cn-cat' => $categoryIDs, 'cn-cat-slug' => FALSE ), $permalink ) );
exit;
}
}
Basically this will globally search the db instead of being limited to the current category whether it is set by the category ID (used by drop down) or category slug (used by category shortcode). And if there is no search but both a category ID and a category slug, the category slug wins and the URL is redirected back to the directory home page filtering by the category selected in the drop down.
Let me know how it goes.
