• Resolved prizraki

    (@prizraki)


    There is a “price” field on the page (from the Advanced Custom Field plugin). There is a home page. There is a TablePress plugin.

    You need to create a table in TablePress. And display it on the main page. The table should display the “price” field from the Advanced Custom Field plugin. I can’t make fields output in TablePress. For some reason, the php code is wrapped in an html comment. And the fields are not displayed. How can I display the price fields in the TablePress plugin?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi!

    Thanks for your post and sorry for the trouble!

    TablePress itself does not have a method to read ACF data. Your best chance probably is to use some sort of Shortcode, either offered directly be ACF or in a separate (maybe custom) plugin.

    Sorry for not having better news here.

    Best wishes,
    Tobias

    Thread Starter prizraki

    (@prizraki)

    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 :))
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    Ah, very nice! Great to hear that you found a solution, and thanks for sharing it!

    Best wishes,
    Tobias

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.