ACF Table Field Pro Add-on Docs

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().

add_filter( 'acf_tablefield/get_table/after_table', function( $html, $param, $table_data ) { 
 
	// $param['field_name'] 
	// $param['post_id'] 
 
	return $html; 
}, 10, 3 );

acf_tablefield/get_table/append_table

This filter enables HTML appending the table using get_table().

add_filter( 'acf_tablefield/get_table/append_table', function( $html, $param, $table_data ) { 
 
	// $param['field_name'] 
	// $param['post_id'] 
 
	return $html; 
}, 10, 3 );

acf_tablefield/get_table/attr/caption

This filter enables filtering the caption HTML element attributes using get_table().

add_filter( 'acf_tablefield/get_table/attr/caption', function( $attr, $data ) { 
 
	$attr['class'][] = 'highlighted'; 
 
	return $attr; 
}, 10, 2 );
echo get_table( 'field_name' ); 
 
// result: 
<caption class="highlighted"></caption>

Parameters

  • data['field']
    • Type: array
    • Description:

      ACF field oject

  • data['selector']
    • Type: string
    • Description:

      Field name or key

  • data['post_id']
    • Type: integer
    • Description:

      The post ID

  • data['item_data']
    • Type: array
    • Description:

      The data of the current table cell

  • data['table_data']
    • Type: integer
    • Description:

      The data of the table

acf_tablefield/get_table/attr/cell

This filter enables filtering table cells HTML element attributes using get_table().

add_filter( 'acf_tablefield/get_table/attr/cell', function( $attr, $data ) { 
 
	$attr['class'][] = 'highlighted'; 
 
	return $attr; 
}, 10, 2 );
echo get_table( 'field_name' ); 
 
// result: 
<td class="highlighted"></td>

Parameters

  • data['field']
    • Type: array
    • Description:

      ACF field oject

  • data['selector']
    • Type: string
    • Description:

      Field name or key

  • data['post_id']
    • Type: integer
    • Description:

      The post ID

  • data['section_key']
    • Type: string
    • Description:

      The table section like thead, tbody or tfoot

  • data['col_index']
    • Type: integer
    • Description:

      The index of the cells column

  • data['item_data']
    • Type: array
    • Description:

      The data of the current table cell

  • data['table_data']
    • Type: integer
    • Description:

      The data of the table

acf_tablefield/get_table/attr/row

This filter enables filtering table rows HTML element attributes using get_table().

add_filter( 'acf_tablefield/get_table/attr/row', function( $attr, $data ) { 
 
	$attr['class'][] = 'highlighted'; 
 
	return $attr; 
}, 10, 2 );
echo get_table( 'field_name' ); 
 
// result: 
<tr class="highlighted"></tr>

Parameters

  • data['field']
    • Type: array
    • Description:

      ACF field oject

  • data['selector']
    • Type: string
    • Description:

      Field name or key

  • data['post_id']
    • Type: integer
    • Description:

      The post ID

  • data['section_key']
    • Type: string
    • Description:

      The table section like thead, tbody or tfoot

  • data['item_data']
    • Type: array
    • Description:

      The data of the current table cell

  • data['table_data']
    • Type: integer
    • Description:

      The data of the table

acf_tablefield/get_table/attr/section

This filter enables filtering table section HTML element (tbody, thead, tfoot) attributes using get_table().

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 );
echo get_table( 'field_name' ); 
 
// result: 
<tbody class="highlighted"></tbody>

Parameters

  • data['field']
    • Type: array
    • Description:

      ACF field oject

  • data['selector']
    • Type: string
    • Description:

      Field name or key

  • data['post_id']
    • Type: integer
    • Description:

      The post ID

  • data['section_key']
    • Type: string
    • Description:

      The table section like thead, tbody or tfoot

  • data['item_data']
    • Type: array
    • Description:

      The data of the current table cell

  • data['table_data']
    • Type: integer
    • Description:

      The data of the table

acf_tablefield/get_table/attr/table

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

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 );
echo get_table( 'field_name' ); 
 
// result: 
<table border="0" class="highlighted" style="width: 50%;"></table>

Parameters

  • data['field']
    • Type: array
    • Description:

      ACF field oject

  • data['selector']
    • Type: string
    • Description:

      Field name or key

  • data['post_id']
    • Type: integer
    • Description:

      The post ID

  • data['table_data']
    • Type: array
    • Description:

      The data of the table

acf_tablefield/get_table/before_table

This filter enables HTML before the table using get_table().

add_filter( 'acf_tablefield/get_table/before_table', function( $html, $param, $table_data ) { 
 
	// $param['field_name'] 
	// $param['post_id'] 
 
	return $html; 
}, 10, 3 );

acf_tablefield/get_table/cell_content

This filter enables changing the content of table cells HTML elements using get_table().

add_filter( 'acf_tablefield/get_table/cell_content', function( $cell_content, $param ) { 
 
	// $param['elem_slug'] 
	// $param['data_key'] 
	// $param['table_options'] 
	// $param['row_options'] 
	// $param['cell_options'] 
	// $param['row_index'] 
	// $param['col_index'] 
 
	return $cell_content; 
}, 10, 2 );

acf_tablefield/get_table/cell_elem

This filter enables changing the HTML element of cells using get_table().

add_filter( 'acf_tablefield/get_table/cell_elem', function( $elem, $param ) { 
 
	// $param['elem_slug'] 
	// $param['data_key'] 
	// $param['table_options'] 
	// $param['row_options'] 
	// $param['cell_options'] 
	// $param['row_index'] 
	// $param['col_index'] 
 
	return $elem; 
}, 10, 2 );

acf_tablefield/get_table/prepend_table

This filter enables HTML prepending the table using get_table(). This filter is for example used to insert the table caption.

add_filter( 'acf_tablefield/get_table/prepend_table', function( $html, $param, $table_data ) { 
 
	// $param['field_name'] 
	// $param['post_id'] 
 
	return $html; 
}, 10, 3 );

acf_tablefield/get_table/sections

This filter is used to register table data sections for get_table().

add_filter( 'acf_tablefield/get_table/sections', function( $sections, $param, $table_data ) { 
 
	// $param['field_name'] 
	// $param['post_id'] 
 
	// Adds a section 
	$sections[] { 
		'elem_slug' => '', // HTML element slug like "tbody" 
		'data_key' => '', // Section key of the returning table data array 
	} 
 
	return $sections; 
}, 40, 3 );

Previous and Next Sources

Parent sources