Home › Forums › Add-ons › Options Page › Field or Variable for use in Group Location
When restricting ACF field groups to certain locations, like only in certain categories, it uses this code:
‘location’ => array (
array (
array (
‘param’ => ‘post_type’,
‘operator’ => ‘==’,
‘value’ => ‘post’,
‘order_no’ => 0,
‘group_no’ => 0,
),
array (
‘param’ => ‘post_category’,
‘operator’ => ‘==’,
‘value’ => ’46’,
‘order_no’ => 1,
‘group_no’ => 0,
),
),
),
In the above example, I was restricting fields to category 46.
My question is this:
Can i create an options page, ask the user to select the categories from a drop down list pre=populated with categories, then use that stored acf field as a variable in the line that reads ‘value’ => ’46’?
So if i set a variable like $my_post_cat = the_field (‘postcats’);
then do something like ‘value’ => ‘$my_post_cat’
Can that work, or am I heading the wrong direction there?
Hi @info@orgspring.com
I’m a bit confused about teh second part of your q, but for the first part: no.
The location rules cannot compare a selected category on the options page, this is a bit too advanced for the current plugin.
That said, you can create custom location rules, so it would not be very hard to create a rule where you can compare the options page’s custom field value!
Thanks
E
I was just using an example, if I create an options page with one drop down select field called ‘postcats’ which would store the id of the category the user selects.
The location of the field group would then be set to display only on the category id.
But you’re saying it can’t be done that way, correct?
I’m not seeing how a custom location rule would get something like that done, since it seems the location rules are based on already set choices, terms, cats, etc. I’m not seeing anything here http://www.advancedcustomfields.com/resources/tutorials/custom-location-rules/ that would hint otherwise.
Im developing something as a plugin to go into sites where i want the custom fields to populate on a specific type of post category, but what one user calls that category might be different than another, hence the reason i want to give them the option to choose which category gets the custom field functionality.
Appreciate your quick response though.
I’m going to switch from basing this on categories to a whole new custom post type. that way I can show the fields based on post type and not worry about drilling down further.
Should eliminate this problem.
thanks for your help and quick response.
The topic ‘Field or Variable for use in Group Location’ 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.