0

I have a custom search with the following line of html in the form:

<input type="hidden" name="post_type" value="product" />

This correctly appends: &post_type=product to the search query in the URL

Unfortunately it returns a blank page.

When I remove the hidden field I get results but obviously none are included from my custom post type.

I have tried disabling plugins to no avail. I have tried swapping out my search.php page with the same file from TwentyFourteen. I have removed the search.php page completely.

I have tried installing plugins that provide the functionality of searching through custom posts to no avail.

This is a woo commerce site and when I use the woo commerce plugin (working fine on other sites) I get the blank page.

Regardless of what I have done I always get the blank page when I add any kind of custom code to my search.

WordPress and plugins are all up to date.

I have spent ages searching for a solution online to no avail.

I am stuck now so am reaching out for assistance with this one.

Any help or guidance would be greatly appreciated.

UPDATE:

After some additional testing I have discovered that this only happens when the post_type being passed to the query string is 'product'. I am using Woo Commerce and am trying to add a search for products to the standard WordPress search.

I still am scratching my head on this one.

  • 1
    can you ellaborate more on what you mean by a blank page? Do you mean there's no content? Do you mean no product posts are ever found? Do you mean there is nothing on the page ( completely blank, no header/footer/sidebar/html of any kind )? What does your error log say? – Tom J Nowell Aug 7 '14 at 14:31
  • Thank you for your question. What I mean is no rendered code at all. I enabled debugging in wp-config but didn't see anything that might relate to the search not working. – Gareth Watson Aug 7 '14 at 15:37
  • It sounds like you have a PHP fatal error, look up PHP error logging and try to track down what the error message is and let us know – Tom J Nowell Aug 7 '14 at 16:19
  • What is the action of the form? Where is it been treated? Maybe you're expecting data from a GET request, but now, as you're POSTing the post_type it doesn't word. If we don't know how you're treating the data on the request it becomes difficult to know whats happening. – Mauricio Moraes Aug 7 '14 at 21:22
  • It's not so much what I am doing as what WP isn't. Adding the hidden field code to the form allows me to target the post_type of product which gets added to the URL as a GET query string. The loop should be able to handle this and return the relevant dataset. The form is successfully adding the query string. When I drop the post_type portion of the query string the results page will load search results but obviously the wrong ones. This leads me to believe that the loop cannot handle the GET query string. This is simple WordPress stuff that generally works out of the box. Am at a genuine loss. – Gareth Watson Aug 7 '14 at 22:36
1

OK, So this is somewhat embarrassing and sorry for wasting everyone's time. When I narrowed down that the issue was just with the products post_type I went and checked what version of Woocommerce was being used and found that it was way out of date. After updating all Woocommerce plugins to the latest versions the product search worked.

One of the first things to do when torubleshooting any issue with Woocommerce or WP in general is typically to ensure all plugins and WP are up to date. I'd like to say that because I did not develop this site and that someone else had been working on it initially that's why I didn't think of checking updates but there are really no excuses. I feel like an idiot!

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.