I found a solution with the help of AI! I needed to output a dynamic field from arbitrary record types page=theme-general-settings in the TablePress table.
To output data from the ACF Theme Options settings page (where page=theme-general-settings) to TablePress, you need to slightly change the shortcode.
The main difference between ACF Theme Options is that instead of a specific post_id, the 'options' parameter is used to receive data.
1. Add a special shortcode
Add this code to functions.php your topic:
// Шорткод для вывода полей из ACF Theme Options: [acf_option field="имя_поля"]
add_shortcode('acf_option', function($atts) {
$atts = shortcode_atts(array(
'field' => '',
), $atts);
if (empty($atts['field'])) return '';
// Получаем значение именно из настроек темы ('options')
$value = get_field($atts['field'], 'options');
// Если значение — массив (например, поле "Изображение" или "Выбор"), преобразуем в строку
if (is_array($value)) {
return isset($value['url']) ? $value['url'] : implode(', ', $value);
}
return $value ? $value : '';
});
2. How to insert into TablePress
Now insert a short command into any cell of your table.:
[acf_option field="phone_number"] — where phone_number is the name (ID) of the field that you specified in the ACF settings.
Why is it convenient for “General Settings”:
- Globality: You can enter the phone number or address in the theme settings once, and it will be updated in all tables of TablePress at once.
- Simplicity: You don’t need to know the page or record ID, just the field name.
An important caveat:
If your field in the ACF is a “Group” or a “Repeater”, the usual output via get_field will return an array and may not be displayed correctly.
If you have a simple text field, rather than a complex element (picture/list), there is another code.
1. Add the code to functions.php
Make sure that this code is added (it is as simplified as possible for the text):
add_shortcode('acf_option', function($atts) {
$atts = shortcode_atts(array('field' => ''), $atts);
if (empty($atts['field'])) return '';
// 'options' — это стандартный идентификатор для ACF Theme Options
return get_field($atts['field'], 'options');
});
2. Insert it into the TablePress
Go to edit your table and write in the appropriate cell: [acf_option field="your_slug_field"]
Don’t thank me.
-
This reply was modified 1 month ago by
prizraki. Reason: There is a solution :))