WordPress.org

Ready to get started?Download WordPress

Forums

custom search.php query custom posts custom fields using meta_query array (2 posts)

  1. Joe Greenwood
    Member
    Posted 2 years ago #

    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. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    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?

  2. bryan042092
    Member
    Posted 2 years ago #

    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. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    did anyone knows what's the wrong with this query?

    tnx in advance...

Topic Closed

This topic has been closed to new replies.

About this Topic