-1

First of all, my post is related to : Link 1 and Link 2

I made my custom taxonomy page. My Custom Taxonomy Page link is

//localhost/myproject/?motion=aamir-khan

This page is custom taxonomy page ( note : no custom page , only custom taxonomy )

But now there is a new requirement of a custom search page in which only my custom taxonomy data will be searched. For example, if any one search "aamir khan", "salman khan", then after submittion, on my custom search button, the same page should be seen as of my custom taxonomy, not default wordpress search page

Hence I added the custom search form below in my header :

<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>

I have placed above custom search button in my header.php

Hence, if any one search with "aamir khan", then the custom taxonomy page should be seen, but I am getting

Page not found

Why page not found? Because, after searching with my custom search form, the link generated is:

//localhost/myproject/?motion=aamir+khan

where, as my custom taxonomy page link generated is:

//localhost/myproject/?motion=aamir-khan

The same when any one search for "salman khan" or any other data:

//localhost/myproject/?motion=salman+khan

but my actual custom taxonomy link generated is:

//localhost/myproject/?motion=salman-khan

In short, if after I've searched, I want my url to be with -, not with +

I want custom search only for my custom taxonomy data page, hence, if url rewriting, then only for custom search form

Note: my default search should not be effected , as I want that too in my website, hence, one wordpress default search button, and another my custom search button, which is only for my custom taxonomy page.

  • @ Aravona : thanks for reply .. the prb is client want same custom taxonomy page after search with custom search button : and this custom search form will only search data of my custom taxonomy page data ...and nothing else .. – user3209031 Jul 7 '14 at 8:18
  • yes u right : but the thing is my custom taxonomy page code is working with Taxonomy SLUG : which use "-" and not "+",hence if i bring the above custom search result to my customsearch.php then also my prb will be same : //localhost/myproject/customsearch.php?motion=salman+khan , hence i taught making another customsearch.php and design code for same ... why not i do some trick to change "+" with "-" for ?motion page ..hence my output will be same for both thats my custom search and custom taxonomy – user3209031 Jul 7 '14 at 8:22
  • cant we do some url rewriting : thats only for my custom search form and custom taxonomy page : thats if localhost/project/?motion=aamir+khan its should redirect to localhost/project/?motion=aamir-khan ...but rewriting should be for ?motion page and not to all my wordpress pages or default search page – user3209031 Jul 7 '14 at 8:28
  • Let us continue this discussion in chat. – Aravona Jul 7 '14 at 8:29
  • Hi Pieter Goosen : any idea on this .. i dont want dropdown search for my custom taxonomy .. i need search with input text – user3209031 Jul 9 '14 at 8:03
0

You can try modifying your query using pre_get_posts filter.

 function mod_query() {
    if ($query->is_main_query() && !is_admin() && is_search()) {

    // test print queried search terms
    print_r( $query->query_vars['s'] );

    $search_terms = $query->query_vars['s'];
    $search_terms = preg_replace('/\s+/', '+', $search_terms);

    // test print after replacing spaces with +
    print_r( $query->query_vars['s'] );

    // if all going well you can change the vars again
    $query->set('s', $search_terms);

    }
 }
 add_filter( 'pre_get_posts', 'mod_query' );

You may need to modify it to get working. But, this can lead you to a solution.

I am not sure - but you may need to change the name='motion' to name='s' as default \ Wordpress name for Search field. I will keep an eye on this thread.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.