Question

I'm using Get Posts plugin to list posts with post type "project". I want to filter the list by two custom fields: year (ex. 2006) and state (ex. Completed). I added meta_query to the plugin's get_post args and tried the shortcode:

[get_posts post_type="project" meta_query="array(array('key' => 'state', 'value' => 
'Completed'),array('key' => 'year','value' => '2006'))" suppress_filters="false"]

This is not working, though I can get both "state" and "year" to work by their own using meta_key and meta_value.

Can someone put me in the right direction?

Was it helpful?

Solution

Besides the plugin not being updated, this will not work because the meta_query arg is evaluated as a string:

array(3) {
  ["post_type"] => string(7) "project"
  ["meta_query"] => string(96) "array(array('key' => 'state', 'value' => 
'Completed'),array('key' => 'year','value' => '2006'))"
  ["suppress_filters"] => string(5) "false"
}

I suggest you make a custom page template, where you would directly call get_posts() with the meta_query you want.

You will have to copy the code that handles the actual listing of the posts.

OTHER TIPS

I don't think the plugin been updated to support the new query args, or specifically in this case, the meta_query arg.

The plugin page lists compatibility upto 3.0.5, and if i remember correctly, meta_query was introduced in 3.1, so naturally i'd conclude support is not yet available..

I could be wrong, just connecting the dots..

The plugin uses shortcode_atts to limit the list of accepted arguments:

http://plugins.trac.wordpress.org/browser/nurelm-get-posts/tags/0.3/get-posts.php#L29

meta_query is not on that list. I'd suggest forking the plugin or asking the author to update it to allow meta queries.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top