• Resolved lituoklis13

    (@lituoklis13)


    Hey, I am try to use your plugin to show tablefield in page which was builded with Elementor. But somehow, table didn’t appear… I am using all the latest version of Elementor and Advanced custom fields, also as Advanced Custom Fields: Table Field.

    I added page link in which table should be but there is not.

    The page I need help with: [log in to see the link]

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

    (@jonua)

    Thread Starter lituoklis13

    (@lituoklis13)

    Hey, Johann. Yes, I did excactly like in instructions. Maybe I can provide you login to my site and you would take a look?

    Plugin Author Johann Heyne

    (@jonua)

    No, I′m not allowed to do that. I will check my instructions against the latest elementor and be back than.

    Plugin Author Johann Heyne

    (@jonua)

    My test was successful. Therefore, there must be something not quite right with your integration. Please check the quotes in the shortcode

    [tablefield field-name="your table field name"]

    are ” not “. This is a common source of errors. Also check, if the Shortcode hook is really integrated somehow by functions.php.

    Cheers, Johann

    Thread Starter lituoklis13

    (@lituoklis13)

    I checked everything and I am sure that quotes are right, also the hook is in functions.php the exact as in your documentation.

    Also I will try to use default theme but there is no luck.

    • This reply was modified 8 months, 3 weeks ago by lituoklis13.
    Plugin Author Johann Heyne

    (@jonua)

    Here are a few questions that might narrow down the problem.

    Is the table preview on the elementor editing page?
    Ist the table field on a page or an option page or somewhere else?
    Is the correct table field name given in the shortcode?
    Is the correct post-id given in the shortcode?
    Has the table more than one cell or at least one cell with content in it?

    Any context helps.

    Thread Starter lituoklis13

    (@lituoklis13)

    Is the table preview on the elementor editing page? I did not see it in elementor editing page, just only the block with grey background, also as others blocks which are showing on frontend corectlly:


    Ist the table field on a page or an option page or somewhere else? Table field is in custom post type page.


    Is the correct table field name given in the shortcode? Yes, I double checked it.


    Is the correct post-id given in the shortcode? Post ID is not given in shortcode.


    Has the table more than one cell or at least one cell with content in it? Yes, I try multiple variations:

    This is the code that I put in functions.php:

    function shortcode_acf_tablefield( $atts ) {
    
        $a = shortcode_atts( array(
            'table-class' => '',
            'field-name' => false,
            'post-id' => false,
        ), $atts );
    
        $table = get_field( $a['field-name'], $a['post-id'] );
    
        $return = '';
    
        if ( $table ) {
    
            $return .= '<table class="' . $a['table-class'] . '" border="0">';
    
                if ( ! empty( $table['caption'] ) ) {
    
                    echo '<caption>' . $table['caption'] . '</caption>';
                }
    
                if ( $table['header'] ) {
    
                    $return .= '<thead>';
    
                        $return .= '<tr>';
    
                            foreach ( $table['header'] as $th ) {
    
                                $return .= '<th>';
                                    $return .= $th['c'];
                                $return .= '</th>';
                            }
    
                        $return .= '</tr>';
    
                    $return .= '</thead>';
                }
    
                $return .= '<tbody>';
    
                    foreach ( $table['body'] as $tr ) {
    
                        $return .= '<tr>';
    
                            foreach ( $tr as $td ) {
    
                                $return .= '<td>';
                                    $return .= $td['c'];
                                $return .= '</td>';
                            }
    
                        $return .= '</tr>';
                    }
    
                $return .= '</tbody>';
    
            $return .= '</table>';
        }
    
        return $return;
    }
    
    add_shortcode( 'tablefield', 'shortcode_acf_tablefield' );

    This is the shortcode that I put in Elementor shortcode element:

    [tablefield field-name="techniniu_duomenu_lentele"]

    And this is Advanced Custom Fields Table Field which I am using:

    • This reply was modified 8 months, 3 weeks ago by lituoklis13.
    • This reply was modified 8 months, 3 weeks ago by lituoklis13.
    Plugin Author Johann Heyne

    (@jonua)

    Thanks, that helped. Your table field is a subfield of another field. Perhaps a repeater field or a group field. Thats why the shortcode wont work. Which type of field ist the parent field? Maybe I can send another updated shortcode.

    Thread Starter lituoklis13

    (@lituoklis13)

    Thanks for your answer, Johann. The table field is inside in a group field.

    Plugin Author Johann Heyne

    (@jonua)

    For table subfields of an field type group, you must update the shortcode hook in the functions with the following:

    function shortcode_acf_tablefield( $atts ) {
    
        $a = shortcode_atts( array(
            'table-class' => '',
            'field-name' => false, // use a slash "/" to separate group field name and table subfield name
            'post-id' => false,
        ), $atts );
    
        // Return if no field name is given
        if ( ! is_string( $a['field-name'] ) ) {
            
            return '';
        }
    
        // May gets sub fields names
        $field_names = explode( '/', $a['field-name'] );
    
        // Gets the root fields value
        $table = get_field( $field_names[0], $a['post-id'] );
    
        // May gets a table subfields value
        foreach ( $field_names as $key => $name ) {
    
            if ( 0 < $key ) {
    
                $table = $table[ $name ];
            }
        }
    
        $return = '';
    
        if ( $table ) {
    
            $return .= '<table class="' . $a['table-class'] . '" border="0">';
    
                if ( ! empty( $table['caption'] ) ) {
    
                    echo '<caption>' . $table['caption'] . '</caption>';
                }
    
                if ( $table['header'] ) {
    
                    $return .= '<thead>';
    
                        $return .= '<tr>';
    
                            foreach ( $table['header'] as $th ) {
    
                                $return .= '<th>';
                                    $return .= $th['c'];
                                $return .= '</th>';
                            }
    
                        $return .= '</tr>';
    
                    $return .= '</thead>';
                }
    
                $return .= '<tbody>';
    
                    foreach ( $table['body'] as $tr ) {
    
                        $return .= '<tr>';
    
                            foreach ( $tr as $td ) {
    
                                $return .= '<td>';
                                    $return .= $td['c'];
                                $return .= '</td>';
                            }
    
                        $return .= '</tr>';
                    }
    
                $return .= '</tbody>';
    
            $return .= '</table>';
        }
    
        return $return;
    }
    
    add_shortcode( 'tablefield', 'shortcode_acf_tablefield' );

    Than you can define the group field name and the table subfield name separated by a slash in the shortcode:

    [tablefield  field-name="group-field-name/table-subfield-name"]
    Thread Starter lituoklis13

    (@lituoklis13)

    Thank you, works perfect!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Table is not showing up with Elementor’ is closed to new replies.