[wp-hackers] Filter custom post type archive page by custom fields

Otto otto at ottodestruct.com
Fri Oct 28 16:34:55 UTC 2011

On Fri, Oct 28, 2011 at 7:43 AM, Alex Hempton-Smith
<hempsworth at gmail.com> wrote:
> Hi all,
> I've been banging my head against a brick wall trying to get this done, so
> hopefully somebody can help.
> I have a custom post type at example.com/people/person
> I have a custom field stored as the following array:
> [0] => array(
>    'title' => 'Manager',
>    'organisation' => 'Acme Inc.'
> ),
> [1] => array(
>    'title' => 'Code Wrangler',
>    'organisation' => 'Code Co.'
> )
> I need to be able to have the following URL filter the results,
> example.com/people/?title=Manager, to show all custom post types with the
> title 'Manager' in their custom field.
> I'm not worried about pretty permalinks for this, just getting it working
> would be fine!
> Does anybody have any suggestions?

Use this for the meta query in your main query.

'meta_query' => array(
	'key' => 'position',
	'value' => '%Manager%',
	'compare' => 'LIKE'

That *might* work. No guarantees. Also, it's not smart. If the name of
the company is "Manager Systems" you'll get that too.

Realistically, you should separate all this data into separate fields
instead of having them in one big array in a single field.


More information about the wp-hackers mailing list