Support

Account

Home Forums General Issues Query Posts using meta data from a Post Object field

Helping

Query Posts using meta data from a Post Object field

  • Hi, I have setup a ‘Person’ custom post type which is pulled through into blog posts using the Post Object field (it lists the people in dropdown) which I have named ‘Author’. This allows me to assign an Author to the post and take advantage of the information already assigned to the Person custom post type e.g. Thumbnail, Bio etc.

    The problem I am having is querying the blog posts to display only posts which have been authored by a particular person. I would usually just query a particular custom field, but because it is a Post Object field I am unsure on how to access the meta data contained within.

    Is this even possible?

  • Hi @quirksmode

    This is achievable through the use of the acf/fields/post_object/query filter. You can modify the $args array as follows:

    function my_post_object_query( $args, $field, $post ) {

    $args[‘author’]=$user_id

    return $args;
    }

    add_filter(‘acf/fields/post_object/query/name=my_post_object’, ‘my_post_object_query’, 10, 3);

    For more info you can refer to this article: acf/fields/post_object/query

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Query Posts using meta data from a Post Object field’ is closed to new replies.