Support

Account

Home Forums General Issues Relationship field: posts from author ID and meta_query Reply To: Relationship field: posts from author ID and meta_query

  • So you have several problems with this query.

    The first being that you cannot do
    {POST AUTHOR} OR {META QUERY} The query being run will always be {POST AUTHOR} AND {META QUERY} and it does not matter that you’ve added 'relation' => 'OR', to the meta query, this only effects the meta query itself. See this information on searching by content or custom fields, the concept here would be similar https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/

    What you need to do is, in your filter above you need to add additional add_filter(..... statements to perform the filtering that will alter the where part of the query in order to do{POST AUTHOR} OR {META QUERY}.

    When you get past that then the next issue it your use of “EXISTS” This just checks that the field exists in the DB and does not compare any value so any value specified is ignored. You are using a field that is stored as a serialized array of user IDs.

    You are also using the field key and not the field name, this will always return false because this meta_key value will never exist, you need to use the field name.

    What you need here is

    
    'meta_query' => array(
      array(
        'key' => 'field-name',
        'value' => '"'.$author_id.'"',
        'compare' => 'LIKE'
      )
    )