Support

Account

Home Forums Add-ons Flexible Content Field Wanting to load a specific Flexible Content field for new posts?

Solved

Wanting to load a specific Flexible Content field for new posts?

  • I have been looking everywhere on options to load specific fields for new posts – eg using Flexible Content fields for blog posts, when the user creates a New Post, there are not fields shown.. and new users are not sure what to start with. So, I want to load the WYSIWYG editor layout when they create a New Post.

    Here is how to do that:

    
    // flexible_content below, is the name of the Flexible Content field
    add_filter('acf/load_value/name=flexible_content', 'add_fields', 10, 3); 
      function  add_fields($value, $post_id, $field) {
        if ($value !== NULL) {  // $value will only be empty for New Posts
          return $value;
        }
        // lead layouts
        $value = array(
          array(
            'acf_fc_layout' => 'heading'
          ),
          array(
            'acf_fc_layout' => 'wysiwyg_editor' // wysiwyg_editor is the name of the layout
          )
        );
        return $value;
      }
    
  • Is “flexible_content” the name of the flex field?

    
    add_filter('acf/load_value/name=flexible_content', 'add_fields', 10, 3);
    

    or are you trying to do this for all flex fields. In this case you probably want to use the field type variation of the hook

    
    acf/load_value/type={$type}
    
  • Yes, “flexible_content” is the name of the flex field I’m wanting to load when a new post or page is created.

    My code solves the issue, I was posting in case anyone else was trying to do the same, but there is no option to mark it as a solution. 🙂

  • Sorry, I misread your post. I thought you were having an issue.

  • All good! I appreciate the reply.

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

You must be logged in to reply to this topic.