Support » Plugin: Advanced Custom Fields: Table Field » Array Push expects parameter 1 to be an array

  • Resolved ktrusak

    (@ktrusak)


    I’m trying to set default values for a CPT when the post is created, however when I try to use the provided code it won’t let me on an empty field. Is there a way to establish the field so I can push rows in?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Johann Heyne

    (@jonua)

    Hi,

    I’m not sure what you trying to do.

    If you want to predefine a table when creating a new Custom Posts entry. Then you would have to create the data of a table in the database as post meta for the corresponding table field. To get the table data, you could create and save the table as desired in that custom post, copy the code from the post meta of that table field from the database and use it for your script to create a predefined table.

    Or if you want the give a default table, if a table is empty…

    $table = get_field( 'your_table_field_name' );
    
    if ( empty ( $table ) ) {
    
        // defining the data of the default table
        $table = array(
            'header' => array(
                'c' => 'Column 1',
            ),
            'body' => array(
                array( // a column
                    array( // a cell of the column
                        'c' => 'Cell Value of Column 1', // the value of the cell
                    ),
                ),
            ),
        );
    
        // output code follows…
        echo '<table border="0">';
        // and so on
    }

    Cheers,
    Johann

    Thread Starter ktrusak

    (@ktrusak)

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Array Push expects parameter 1 to be an array’ is closed to new replies.