Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$4
Search with Custom Fields in search.php
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
This question has been answered.
Muhammad Adnan | 04/01/11 at 6:27am
Edit
The experts have suggested, on average, a prize of $10 for this question.
(1) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
04/02/11
7:26amAdamGold says:query_posts($query_string."&paged=$paged&meta_key=location&meta_value=".$_GET['meta_value']."&orderby=title&order=ASC");
It should work.- 04/01/11 6:35am
Muhammad Adnan says: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'
- 04/01/11 6:37am
AdamGold says:Works, isn't it?
- 04/01/11 6:38am
Muhammad Adnan says: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 .. ?? - 04/01/11 6:40am
AdamGold says:Ok. What exactly do you want it to show? Please use Google Translate so I can understand your words.
- 04/01/11 6:43am
Muhammad Adnan says: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 ? - 04/01/11 6:48am
AdamGold says:Try to use this plugin:
http://wordpress.org/extend/plugins/wp-custom-fields-search/ - 04/01/11 6:50am
Muhammad Adnan says:oh no, I don't want to use the plugin :(
there is no solution without plugin ? - 04/01/11 6:51am
AdamGold says:Well I guess you can, check out this tutorial:
http://tobymackenzie.wordpress.com/2009/11/18/stearns-wordpress-custom-queries/ - 04/01/11 7:10am
Muhammad Adnan says: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"); - 04/01/11 7:27am
AdamGold says:Are you sure your meta key name is cp_state? BTW please raise your prize.
- 04/01/11 7:31am
Muhammad Adnan says:yes, it is sure cp_state.
btw, I can go max. $10 if I got what I wanted.
otherwise it is a waste :( - 04/01/11 7:33am
AdamGold says:It should work, what's the problem?
- 04/01/11 7:34am
Muhammad Adnan says: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 ? - 04/01/11 7:38am
AdamGold says:Try to print the $_GET variable and tell me its output.
var_dump($_GET); - 04/01/11 7:40am
Muhammad Adnan says: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" } - 04/01/11 7:42am
AdamGold says:That's really weird. Are you sure the meta key is cp_state and not something else?
- 04/01/11 7:45am
Muhammad Adnan says:see attached.
- 04/01/11 8:02am
AdamGold says:Try to use get_posts
global $post;
$args = array( 'pages' => $pages, 'meta_key'=> 'cp_state', 'meta_value' => $_GET['meta_value'], 'orderby' => 'title', 'order' => 'ASC' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
your html code
<?php endforeach; ?>
- 04/01/11 5:42pm
Muhammad Adnan says:I found the solution myself.
should I post it here ? or select the winner ? - 04/02/11 1:07am
AdamGold says:As you want.. What is the solution?
- 04/02/11 7:02am
Muhammad Adnan says:We should use filter posts_where that was the best solution.
- 04/02/11 7:23am
AdamGold says:Okay. glad you figured it out.
- 04/01/11 6:35am
This question has expired.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
