Horje
Search with Custom Fields in search.php - Wordpress Solution
hi experts, I'm messing with search.php to use custom fields in it. If you go to this site http://elook.ie/ and see the top search box. I added a custom field "location" I need to perform the search based on 3 things. 1. keywords 2. category 3. location i.e custom field Following is the code I'm using..

global $query_string;
query_posts($query_string."&paged=$paged&meta_value=".$_GET['meta_value']."&orderby=title&order=ASC");
I need it done ASAP. THanks
query_posts($query_string."&paged=$paged&meta_key=location&meta_value=".$_GET['meta_value']."&orderby=title&order=ASC");
It should work. Thanks for so fast reply. I uploaded your solution to site. I want you to make a sample search with location 'Kentucky' and ads should return all ads with that location 'Kentucky' Works, isn't it? hmm, have a look at this URL http://elook.ie/?s=boys&sa=search&cat=0&meta_value=Kentucky s=boys meta_value=Kentucky it should only return kentucky ads .. ?? Ok. What exactly do you want it to show? Please use Google Translate so I can understand your words. I want to show the posts depending on the selection criteria i.e keyword,category,custom field [location] So, It should return only those ads depending on the custom field [location]. if keywords are empty, it should just return the results based on category and location. I hope you got my point now ? Try to use this plugin: http://wordpress.org/extend/plugins/wp-custom-fields-search/ oh no, I don't want to use the plugin :( there is no solution without plugin ? Well I guess you can, check out this tutorial: http://tobymackenzie.wordpress.com/2009/11/18/stearns-wordpress-custom-queries/ can u tell me why this is not working ?
query_posts($query_string."&paged=$paged&meta_key=cp_state&meta_value=".$_GET['meta_value']."&orderby=title&order=ASC");
Are you sure your meta key name is cp_state? BTW please raise your prize. yes, it is sure cp_state. btw, I can go max. $10 if I got what I wanted. otherwise it is a waste :( It should work, what's the problem? go here http://elook.ie/?s=boys&sa=search&cat=0&meta_value=Co.%20Derry it should just return the 1 ad with location 'Co. Derry' isn't it ? Try to print the $_GET variable and tell me its output.
var_dump($_GET);
refresh the page now and you will see output http://elook.ie/?s=boys&sa=search&cat=0&meta_value=Co.%20Derry
array(4) { ["s"]=> string(4) "boys" ["sa"]=> string(6) "search" ["cat"]=> string(1) "0" ["meta_value"]=> string(9) "Co. Derry" }
That's really weird. Are you sure the meta key is cp_state and not something else? see attached.

Solution - 1

query_posts($query_string."&paged=$paged&meta_key=location&meta_value=".$_GET['meta_value']."&orderby=title&order=ASC");
It should work.





Wordpress

Related
WP Email Capture in WP PopUp Scheduler - Wordpress Solution WP Email Capture in WP PopUp Scheduler - Wordpress Solution
Problem with Tweetable plugin - Wordpress Solution Problem with Tweetable plugin - Wordpress Solution
My home page and sidebar content is cut off  - Wordpress Solution My home page and sidebar content is cut off - Wordpress Solution
Title Duplication Warning - Wordpress Solution Title Duplication Warning - Wordpress Solution
Twitter Plugin that only shows users tweets - Wordpress Solution Twitter Plugin that only shows users tweets - Wordpress Solution

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8