Support

Account

Home Forums General Issues get_field() related_posts [only publish posts] Reply To: get_field() related_posts [only publish posts]

  • This is something recent and I do not know when this was changed. As I said, at one time get_field() on the front of the site would only return published posts and/or any post the the current visitor was allowed to see. Now both post object and relationship fields call the function acf_get_psots() and this function forces 'post_status' => 'any' and there are no filter hooks available in ACF to modify this.

    Currently there are two choices

    1. use the pre_get_posts example I provided above. Added note: I thing setting post_status to false will revert to ACF’s previous behavior $query->set('post_status', false);
    2. set the field to return post IDs or get the field without formatting by setting the 3rd argument of get_field() to false and then do your own query with post__in on the array of ID values and orderby “post__in”

    Beyond this the only advice I can give to to contact the developers. It appears that this function is used on both front and back end queries now and without adding them adding a filter to alter this in the format_value function for the field I don’t see any other way around this issue at this time.