WordPress.org

Ready to get started?Download WordPress

Forums

[closed] pre_get_posts meta_query nested array not working (3 posts)

  1. wendallsan2
    Member
    Posted 6 months ago #

    In my pre_get_posts function, setting the meta_query returns no results if it is a nested array. It works fine with a single (non-nested) array passed, but this is not how the documentation explains this feature and I actually do need to to filter with multiple meta_queries.

    This works, even though according to the documentation it should not, as I am not setting the meta_query to a nested array:

    $meta_query = array( 'key' => 'author', 'value' => $member_ids, 'compare' => 'IN' );
    $query->set('meta_query', $meta_query);

    This does not work (returns no results, even though I have posts that match both meta_query criteria):

    $meta_query = array();
    $meta_query[] = array( 'key' => 'author', 'value' => $member_ids, 'compare' => 'IN' );
    $meta_query[] = array( 'key' => 'mpl_pal_share_pal', 'value' => 1 )
    $query->set('meta_query', $meta_query);

    This also does not work (this is the same thing as the first example above, which does work, except now it is nested in another array, which is how the documentation says it needs to be):

    $meta_query = array();
    $meta_query[] = array( 'key' => 'author', 'value' => $member_ids, 'compare' => 'IN' );
    $query->set('meta_query', $meta_query);

    Again, I expect this last example should work exactly like the first example, in that it has the same exact meta_query, and the only difference is that it is nested in an array. According to the documentation (http://codex.wordpress.org/Class_Reference/WP_Query) the meta_query needs to be a nested array, but this is absolutely not working for me. Any nested array return no results. If it is not a nested array, it works great, but I then cannot query using multiple meta_queries, which is what I need. Any help?

  2. magicroundabout
    Member
    Posted 1 month ago #

    I seem to be struggling with this too. Do you know if it was logged as a bug or anything? Seems to be no response!

  3. esmi
    Forum Moderator
    Posted 1 month ago #

    If you require assistance then, as per the Forum Welcome, please post your own topic instead of tagging onto someone else's topic.

    I am now closing this 4 month old topic as it references an older version of WordPress.

Topic Closed

This topic has been closed to new replies.

About this Topic