Title: custom search.php query custom posts custom fields using meta_query array
Last modified: August 20, 2016

---

# custom search.php query custom posts custom fields using meta_query array

 *  [Joe Greenwood](https://wordpress.org/support/users/jgreenwood/)
 * (@jgreenwood)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/custom-searchphp-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:
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   The maximum number of lines of code that you can post in these forums is **ten
   lines**. Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * 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?

Viewing 1 replies (of 1 total)

 *  [bryan042092](https://wordpress.org/support/users/bryan042092/)
 * (@bryan042092)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/custom-searchphp-query-custom-posts-custom-fields-using-meta_query-array/#post-2580213)
 * 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.
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome#Posting_Code).
   The maximum number of lines of code that you can post in these forums is **ten
   lines**. Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * did anyone knows what’s the wrong with this query?
 * tnx in advance…

Viewing 1 replies (of 1 total)

The topic ‘custom search.php query custom posts custom fields using meta_query array’
is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)
 * [meta_query](https://wordpress.org/support/topic-tag/meta_query/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bryan042092](https://wordpress.org/support/users/bryan042092/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/custom-searchphp-query-custom-posts-custom-fields-using-meta_query-array/#post-2580213)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
