I have built out a property listing module using custom post types and custom meta fields. One of the features i've built in is the ability to select multiple Listing Agents, which have been entered into another custom post type called agents. I was able to get this to work, and can even save, and list the multiple agents on the front end, and display which ones have been selected in the backend multiple select field. Saving multiple agents is where my issue stems from though.
One of my clients requests was to show a list of "Properties" based on which agent is assigned, in this way I can have a link on my Agent details page that goes to a list of their properties. So I used the following code at the top of my properties archive template:
$thekey = $_GET['thekey']; $thevalue = $_GET['thevalue']; $args = array( 'post_type' => 'properties', 'showposts' => 10, 'meta_query' => array( array( 'key' => $thekey, 'value' => $thevalue, 'compare' => '=' ) ) );
This code works if I add http://sitename.com/properties?thekey=city&thevalue=cityname and pulls a list of only certain cities with the value entered in. I was able to get this to work for all of my fields but one, the agents.
The issue I think I have is that all my other custom meta data fields only store 1 value, whereas the "Select Agents" meta data field is storing an array of agents.
My question is, does anyone know why doing a meta_value query for a meta field storing an array doesn't work? Or what I can do to make it work?
If you need more samples of my code to figure out what else i'm doing here, let me know. This is the last thing standing between me and a completed project, so any help would me immensely appreciated.