Support

Account

Home Forums Bug Reports Format value hook does not work for type=post_object

Solved

Format value hook does not work for type=post_object

  • Hello
    I’m using the format value hook to add fields to returned post objects
    using https://www.advancedcustomfields.com/resources/acf-format_value/

    When specifying specific key, it works like a charm. However, when using type=post_object, it causes errors (trying to assign the value to fields that are not post_objects like ints and booleans)

    As a result, i had to manually add filters to every single post_object key.. it works but not ideal

    Possible to fix?
    Cheers

  • for a post object field ACF is returning whatever you have selected. So what you can do with it would depend on your return format. You also need to make sure that your filter runs with a priority > 10 in order to allow ACF to do it’s formatting first.

  • Wow. It works!
    I feel a little dumb haha

    I truely wonder why it works for me when using key= or name= tho

    With > 10 priority, i was able to simply use type=post_object and clean my code

    Thank you 🙂

  • The reason

    ACF uses it’s own hooks to format the fields at priority 10. In other words ACF formats a post object field when the acf/format_value/type={$type} hook variant fires. This hook variant is fired before the other variants. This means that when the other variants fire ACF has already formatted the value on the type={$type} variant hook. So the priority for the other variants does not matter.

    When in doubt always add a priority > 10 for all ACF filter and action hooks because ACF uses them too.

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

You must be logged in to reply to this topic.