Home Forums Add-ons Flexible Content Field flexible content – appear automatically


flexible content – appear automatically

  • Hi,

    I recently bought addon flexible content.

    I have custom post called product and i’m attaching fileds to that custom post type.

    I am wondering is it possible to make that fields are automatically shown when I’m in products without clicking add new row?

    Also i want to disable add new row button so that moderator cannot mess with it.

    Kind regards.

  • Here is an example of adding two default layouts to a new post

      add_filter('acf/load_value/name=flexible', 'add_starting_repeater', 10, 3);
      function  add_starting_repeater($value, $post_id, $field) {
        if ($value !== NULL) {
          // $value will only be NULL on a new post
          return $value;
        // add default layouts
        $value = array(
            'acf_fc_layout' => 'layout_1' // layout_1 is the name of the layout
            'acf_fc_layout' => 'layout_1'
        return $value;
  • So basically i need to create all my layouts and called them using code above in my functions.php file?

  • Yes, you could do that if you want to automatically insert one of each layout into a new post.

  • This is not working, i need to all custom fields to appear in wp dashboard in custom post type product when user enters it so he deosnt need to click add new row and…

  • I guess that depends on what the custom fields are, also if you want to also add content ahead of time. What I gave you only covers automatically adding the layouts. If these have repeater fields as well then they would not be shown.

    It would be virtually impossible for me to tell you how to get all the fields to display and this is not something that I’m going to build for you.

    What you need to do:

    1) Create an example post with all the fields you want to be shown automatically and include either the default content or some example content

    2) Edit the load_value function to add this at the top of the function echo '<pre>';print_r($value); echo '</pre>'. This will display what the value needs to be set to in your function.

    The value may be hidden by CSS, you might need to look at the code of the output page or dig around with a code inspector.

    3) Build the array needed to populate your field using the example.

    To be honest it seems like a lot of trouble so that someone can avoid learning how to use the interface and not have to click a button to add a row, at least to me.

  • why use flexible content when you like to disable add new, and also like to have all fields published from beginning?

  • @mediawerk has a point. If all of the fields need to be there then it is not a very good use of flexible content. The entire reason for using it is to give the client or user the choice of what to a page will look like. You’d be better off creating a field group with tabs and putting fields in each tab for the different sections of the page. Or any number of other solutions that do not require the user to add anything.

  • Hi guys, thanks for the reply, but it is necessary for me to do that this way.

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

You must be logged in to reply to this topic.