Home Forums ACF PRO Using acf/fields/post_object/query with subfields/repeater


Using acf/fields/post_object/query with subfields/repeater

  • Hi

    I have the following filter which sorts a Page Link dropdown in date order and does a couple of other things too:

    function relationship_options_filter($args, $field, $post_id) {
      $args['post_status']  = array('publish'); // Hide drafts
      $args['post__not_in'] = array($post_id); // Hide current post
      $args['order']        = 'DESC';
      $args['orderby']      = 'date';
      return $args;
    add_filter('acf/fields/post_object/query/name=related_project', 'relationship_options_filter', 10, 3);

    Works fine for regular fields, but I can’t get it to work for subfields on repeaters. My guess from this page:

    was try using the field key (obtained looking at phpMyAdmin), but that would appear to be a reference to the repeater itself (and doesn’t work, neither does using the name, eg: homepage_news_news_items_0_link). I’m a bit hazy around what to try next.

    Anyone have any pointers?

    Thanks in advance!


  • Hi Ben,

    I was unable to duplicate the issue you are having. I was able to successfully use your filter verbatim when my field was and wasn’t a subfield in a repeater.

    However, the filter: acf/fields/post_object/query is meant for the Post Object type, not the Page Link type. So… it shouldn’t have worked at all for you, subfield or not, if using a Page Link field, right?

    Are you able to switch to a Post Object instead without having to change too much else around?

  • I can’t believe I did that.

    Of course it should be a Post Object; the original usage was a Post Object. I think that somehow because they behave the same in the editor I was blinded by the obviousness of it.

    Thanks Keith!

    For anyone else who has this issue, I did find that only the key of the subfield itself, not the name worked for me.

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

The topic ‘Using acf/fields/post_object/query with subfields/repeater’ is closed to new replies.