Reputation: 835
I have made Custom Taxonomy Page : aamir khan , salman khan , aab cc ..etc hence its link are :
localhost/myproject/?motion=aamir-khan
.. llly for others.
Now i want Custom Search form : where any one search aamir khan .. its should show same custom taxonomy page of aamir khan.below is my custom search form :
<form role="customsearch" method="get" id="customsearchform" action="<?php echo home_url('/'); ?>">
<div>
<label for="s">Search for:</label>
<input type="text" value="" name="motion" id="motion" />
<input type="submit" id="customsearchsubmit" value="Search Motion" />
</div>
</form>
but when i search with aamir khan in above search form its show me " Page not found "
as link generated is
localhost/myproject/?motion=aamir+khan
i know aamir khan both will be read as different word in search "GET" .. hence its showing "+"...
hence what is best way ..so that i can search taxonomy data and result outlook should be same as my custom taxonomy page ...
Note: i am not using custom post ...
also i want input field custom search for custom taxonomy ... not drop-down search ..
Upvotes: 0
Views: 784
Reputation: 11808
The solution given below will work with the current configuration of WordPress only.
Usually, people are going to search by Term name and not slug. Therefore, we will have to find out the slug from the value inputted by end user and then WordPress will show the content for that term.
Add below code in functions.php file
add_action('init', 'wdm_change_motion_slug');
function wdm_change_motion_slug()
{
if(isset($_GET['motion']) && !empty($_GET['motion']))
{
$term = term_exists($_GET['motion'], 'motion'); //Check if the term already exists
if ($term !== 0 && $term !== null)
{
$_GET['motion'] = get_term_by('id', (int)$term['term_id'], 'motion')->slug; //Find out slug of term from the term id
}
}
}
Let me know, if it solves the issue.
Upvotes: 1