Home › Forums › General Issues › Location Array not updating after PHP Import
Elliot,
Fantastic plugin. Here is my issue:
On MAMP, I originally created a theme using the ACF plugin to add some custom fields to just one custom post type. Worked great.
I exported the ACF options via PHP, then included the plugin in my theme, added the exported PHP to my functions file, then loaded the theme to a live site on the web.
I now need to add the custom fields to more than just the one custom post type. So I found this:
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'poles',
'order_no' => 0,
'group_no' => 0,
),
),
),
And I turned it into this:
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'poles',
'order_no' => 0,
'group_no' => 0,
),
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'finials',
'order_no' => 1,
'group_no' => 0,
),
),
),
The problem is – it won’t register on more than one post type. When I added the additional location, it didn’t show up in either post type! I have tried everything I could and searched the forums and have found no answer. It simply won’t register in multiple locations (post types). I even tried adding ‘all’ as the post type.
I am now using the last version of ACF as a plugin instead of bundled with the theme. Any help would be greatly appreciated.
Hi @lesgrossman
The issue is that your location rule is not written correctly. Can you please create a new field group in the backend of WP with the desired location rules, then export the field group and just copy / paste the location rules out.
The issue in particular is that your array is nested incorrectly.
Following my above advice will demonstrate how the nesting should look.
Thanks
E
Elliot,
This is something that I actually tried. Here are the location rules it exports right now:
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'finials',
'order_no' => 0,
'group_no' => 0,
),
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'holdbacks',
'order_no' => 1,
'group_no' => 0,
),
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'endcaps',
'order_no' => 2,
'group_no' => 0,
),
),
),
Are you seeing something that I am not? I can’t figure what’s different between this and the original. This is how the latest version of ACF exports it for me now.
Thank you!
Hi @lesgrossman
Your location rules are written like this.
Show the field group if:
* post_type == finials
* AND post_type == holdbacks
The issue is that this will never return true. A post can only be of 1 type, not 2 or 3.
To change the AND to OR, your grouping needs to change to this:
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'finials',
'order_no' => 0,
'group_no' => 0,
),
),
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'holdbacks',
'order_no' => 1,
'group_no' => 0,
),
),
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'endcaps',
'order_no' => 2,
'group_no' => 0,
),
),
),
If you had created a new field group and added the rules correctly (into OR groups), this is how the code should have exported
The topic ‘Location Array not updating after PHP Import’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.