Home › Forums › Feature Requests › Filter for flexible content layouts › Reply To: Filter for flexible content layouts
There is nothing in ACF that can do this and you have to build something yourself. This would be the equivalent of having location rules for every field.
I had the same need a few months ago, in my case I needed to show a layout only on a specific post type.
I created an acf/load_field filter https://www.advancedcustomfields.com/resources/acf-load_field/ for the flex field. I then checked the post type of the post. Then I looped through the layouts in the field settings and removed the ones I didn’t want to show.
The best I can offer you is the code I used to remove the layouts I did not want to show on other post types
// this is an excerpt from my load field filter
// above here I decided if the layouts should be shown
// if not then this code would run
$layouts = $field['layouts'];
$field['layouts'] = array();
foreach ($layouts as $layout) {
if ($layout['name'] != 'product_panel' && $layout['name'] != 'product_specs_panel') {
$field['layouts'][] = $layout;
}
}
return $field;
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.