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 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;