Home Forums Backend Issues (wp-admin) Issue / Change with Location Rules in ACF 5


Issue / Change with Location Rules in ACF 5

  • I have a custom location rule I created a while back as per these instructions:

    Worked fine until the upgrade to ACF 5. Finally got a chance to dig in and take a look and turns out the issue is that in acf/location/rule_match/$type the value of $options[‘post_taxonomy’] is always an array with an empty first value.

    My filter allows users to specify locations based on a custom taxonomy name, Ex: Fee Type. So instead of choosing Post Taxonomy (my users would probably have no idea what that means) they can choose a location based on Fee Type = Something.

    When you create a new post and select a Fee Type for it ACF fires off an ajax call that returns data about the post in $options. $options[‘post_taxonomy’] returns something like:
    array( 0 => , 1 => 8 )

    I updated my function to drop the first element of in the array if it is empty (which in testing it always is, but better to check just in case). Posting this here in case anyone else is running into a similar issue and/or that’s not the intended response and it’s a potential bug.

  • Hi @wunderdojo

    Could you please share your custom location code so I can test it out on my installation?


  • Sure thing, here you go:

    One key thing to note is that for my use case there is a custom post type called Products. Products have a custom taxonomy, Fee Type. Each product should only have a single fee type associated with it so in line 71 I’m using array_pop to grab the last value from the taxonomy array that ACF is returning.

    In other words, ACF returns an array like ( 0=> , 1 => 8 ). In my use case there will only ever be a single taxonomy selected so I just grab the second (last) value in the array. If you allow multiple taxonomies you’d want to switch the comparison logic to use in_array() or keep it as is but loop through for each value in the array.

  • Hi @wunderdojo

    Thanks for the code.

    I’ve just tested the post category, and it seems it has the same behaviour too. It’s possible that this is intended. I’ll pass this issue to the plugin author and hope he has a better explanation.


  • Hi @wunderdojo

    I’ve just done some debugging through the ACF ajax JS and found that yes, the empty array value is required.

    Without the empty array value, jQuery won’t post the array, and ACF won’t know that the post’s term’s have been modified.

    Continue using your array_pop, or consider using in_array


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

The topic ‘Issue / Change with Location Rules in ACF 5’ is closed to new replies.