ACF Table Field Pro Add-on Docs Last updated:

Select plugin version:

Since version: v1.0.0

View Table with PHP

Get a HTML Table

Basic example

$table_data = get_field('acf_field_name'); 
echo get_table( $table_data );

Function: get_table()

The get_table() PHP function takes the fields data and returns an HTML table. There are following filters to hook into the returning table HTML.

Filters

acf_tablefield/get_table/after_table

This filter enables HTML after the table using get_table() or other table HTML returning functions and methodes.

Parameters

add_filter( 'acf_tablefield/get_table/after_table', function( $html, $param, $table_data ) { 
 
	return $html; 
}, 10, 3 );
    • $html
    • (string)
    • HTML string of the previously added HTML.

    • $param['field_name']
    • (string)
    • $param['post_id']
    • (integer)
    • $param['field']
    • (array)
    • The ACF field object

    • $table_data
    • (array)
    • The table data.

acf_tablefield/get_table/append_table

This filter enables HTML appending the table using get_table() or other table HTML returning functions and methodes.

Parameters

add_filter( 'acf_tablefield/get_table/append_table', function( $html, $param, $table_data ) { 
 
	return $html; 
}, 10, 3 );
    • $html
    • (string)
    • HTML string of the previously added HTML.

    • $param['field_name']
    • (string)
    • $param['post_id']
    • (integer)
    • $param['field']
    • (array)
    • The ACF field object

    • $table_data
    • (array)
    • The table data.

acf_tablefield/get_table/attr/caption

This filter enables filtering the caption HTML element attributes using get_table() or other table HTML returning functions and methodes.

Parameters

add_filter( 'acf_tablefield/get_table/attr/caption', function( $attr, $data ) { 
 
	$attr['class'][] = 'highlighted'; 
 
	return $attr; 
}, 10, 2 );
    • $attr
    • (array)
    • A key value pair array of the html element attributes.

    • $data['field']
    • (array)
    • ACF field oject

    • $data['selector']
    • (string)
    • Field name or key

    • $data['post_id']
    • (integer)
    • The post ID

    • $data['item_data']
    • (array)
    • The data of the current table cell

    • $data['table_data']
    • (integer)
    • The data of the table

Result

<caption class="highlighted"></caption>

acf_tablefield/get_table/attr/cell

This filter enables filtering table cells HTML element attributes using get_table() or other table HTML returning functions and methodes.

Parameters

add_filter( 'acf_tablefield/get_table/attr/cell', function( $attr, $data ) { 
 
	$attr['class'][] = 'highlighted'; 
 
	return $attr; 
}, 10, 2 );
    • $attr
    • (array)
    • A key value pair array of the html element attributes.

    • $data['field']
    • (array)
    • ACF field oject

    • $data['selector']
    • (string)
    • Field name or key

    • $data['post_id']
    • (integer)
    • The post ID

    • $data['section_key']
    • (string)
    • The table section like thead, tbody or tfoot

    • $data['col_index']
    • (integer)
    • The index of the cells column

    • $data['row_index']
    • (integer)
    • The index of the cells row

    • $data['item_data']
    • (array)
    • The data of the current table cell

    • $data['table_data']
    • (integer)
    • The data of the table

    • $data['manager_id']
    • (string)
    • The table manager id if set.

Result

<td class="highlighted"></td>

acf_tablefield/get_table/attr/row

This filter enables filtering table rows HTML element attributes using get_table() or other table HTML returning functions and methodes.

Parameters

add_filter( 'acf_tablefield/get_table/attr/row', function( $attr, $data ) { 
 
	$attr['class'][] = 'highlighted'; 
 
	return $attr; 
}, 10, 2 );
    • $attr
    • (array)
    • A key value pair array of the html element attributes.

    • $data['field']
    • (array)
    • ACF field oject

    • $data['selector']
    • (string)
    • Field name or key

    • $data['post_id']
    • (integer)
    • The post ID

    • $data['section_key']
    • (string)
    • The table section like thead, tbody or tfoot

    • $data['col_index']
    • (integer)
    • The index of the cells column

    • $data['row_index']
    • (integer)
    • The index of the cells cow

    • $data['item_data']
    • (array)
    • The data of the current table cell

    • $data['table_data']
    • (integer)
    • The data of the table

    • $data['manager_id']
    • (string)
    • The table manager id if set.

Result

<tr class="highlighted"></tr>

acf_tablefield/get_table/attr/section

This filter enables filtering table section HTML element (tbody, thead, tfoot) attributes using get_table() or other table HTML returning functions and methodes.

Parameters

add_filter( 'acf_tablefield/get_table/attr/section', function( $attr, $data ) { 
 
	if( 'tbody' !== $data['section_key'] ) { 
 
		return $attr; 
	} 
 
	$attr['class'][] = 'highlighted'; 
 
	return $attr; 
}, 10, 2 );
    • $attr
    • (array)
    • A key value pair array of the html element attributes.

    • $data['field']
    • (array)
    • ACF field oject

    • $data['selector']
    • (string)
    • Field name or key

    • $data['post_id']
    • (integer)
    • The post ID

    • $data['section_key']
    • (string)
    • The table section like thead, tbody or tfoot

    • $data['item_data']
    • (array)
    • The data of the current table cell

    • $data['table_data']
    • (integer)
    • The data of the table

    • $data['manager_id']
    • (string)
    • The table manager id if set.

Result

<tbody class="highlighted"></tbody>

acf_tablefield/get_table/attr/table

This filter is used in get_table() or other table HTML returning functions and methodes and enables to filter/add/remove attributes and their values of the <table> element.

Parameters

add_filter( 'acf_tablefield/get_table/attr/table', function( $attr, $data ) { 
 
	$attr['border'] = '0'; 
 
	$attr['class'][] = 'highlighted'; 
	$attr['style'][] = 'width: 50%;'; 
 
	return $attr; 
}, 10, 2 );
    • $attr
    • (array)
    • A key value pair array of the html element attributes.

    • $data['field']
    • (array)
    • ACF field oject

    • $data['selector']
    • (string)
    • Field name or key

    • $data['post_id']
    • (integer)
    • The post ID

    • $data['table_data']
    • (array)
    • The data of the table

    • $data['manager_id']
    • (string)
    • The table manager id if set.

Result

<table border="0" class="highlighted" style="width: 50%;"></table>

acf_tablefield/get_table/before_table

This filter enables HTML before the table using get_table() or other table HTML returning functions and methodes.

Parameters

add_filter( 'acf_tablefield/get_table/before_table', function( $html, $param, $table_data ) { 
 
	return $html; 
}, 10, 3 );
    • $html
    • (string)
    • HTML string of the previously added HTML.

    • $param['field_name']
    • (string)
    • $param['post_id']
    • (integer)
    • $param['field']
    • (array)
    • The ACF field object

    • $table_data
    • (array)
    • The table data.

acf_tablefield/get_table/cell_content

This filter enables changing the content of table cells HTML elements using get_table() or other table HTML returning functions and methodes.

Parameters

add_filter( 'acf_tablefield/get_table/cell_content', function( $cell_content, $param ) { 
 
	return $cell_content; 
}, 10, 2 );
    • $cell_content
    • (string)
    • The content of the cell.

    • $param['elem_slug']
    • (string)
    • $param['data_key']
    • (string)
    • $param['table_options']
    • (array)
    • $param['row_options']
    • (array)
    • $param['cell_options']
    • (array)
    • $param['row_index']
    • (integer)
    • $param['col_index']
    • (integer)

acf_tablefield/get_table/prepend_table

This filter enables HTML prepending the table using get_table() or other table HTML returning functions and methodes. This filter is for example used to insert the table caption.

Parameters

add_filter( 'acf_tablefield/get_table/prepend_table', function( $html, $param, $table_data ) { 
 
	return $html; 
}, 10, 3 );
    • $html
    • (string)
    • HTML string of the previously added HTML.

    • $param['field_name']
    • (string)
    • $param['post_id']
    • (integer)
    • $param['field']
    • (array)
    • The ACF field object

    • $table_data
    • (array)
    • The table data.

Previous and Next Sources

Parent sources