custom search.php query custom posts custom fields using meta_query array
In my theme I have a custom search template, search.php ..
I have some code to run a query of custom field values in some custom posts. They are classified ads, these custom posts, and the custom fields are things like ‘make’, ‘model’, ‘year’, ‘color’, etc. I want to allow people to be able to search by make, model, year, color, price, etc.
So it is a straight-forward query_posts of the arguments of ‘post_type’, ‘paged’, and then the custom field queries in a ‘meta_query’ array:
The problems I am having are this:
– using any more than exactly 8 of those key-value pair arrays in the meta_query array causes my search to query and query endlessly and never (or at least as long as I was willing to wait) return a page, not even a 404 not found WP page. If I use 8 or less of those key-value pair arrays within the meta_query array, I’m okay, I get a search results page from WP.
So the question here is, why is there a limit? Is there a limit? Or am I just doing something wrong?
– the next problem I am having is that after experimenting with the above code, maybe an hour or several later, my site crashes, telling me:
“Warning: mysql_connect() [function.mysql-connect]: User vg_blog already has more than ‘max_user_connections’ active connections in /home/vg/public_html/wp-includes/wp-db.php on line 1034
Error establishing a database connection”
.. which thankfully I know how to resolve through my web host (they raise the limit of max connections) .. and I am lead to believe that my meta_query array is causing this. My bad query_posts code is not only not returning search results, it is also crashing my database!
So, I am wondering … anyone can help me figure out the right way to do this search of the custom fields?
Hi Joe Greenwood!,
I’m also having a problem in doing the right query for a custom search. Instead of using the built in search funtion in wordpress thesis, i created a custom form that will pass data to other page, for my search which has 5 fields for the filters. I’m using a simple field plugin for my custom field.
did anyone knows what’s the wrong with this query?
tnx in advance…
- The topic ‘custom search.php query custom posts custom fields using meta_query array’ is closed to new replies.