Get Posts shortcode plugin and meta_query?

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.

Read More

Can someone put me in the right direction?

Related posts

Leave a Reply

3 comments

  1. 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.

  2. 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..