• Resolved nikkofir

    (@nikkofir)


    I’ve prevented ACFCT from storing data in wp_postmeta via the acf_ct/settings/store_acf_values_in_post_meta==false filter

    My use scenario generated 150,000+ rows in the wp_postmeta table so it’s important for me to only store my custom post/field data in the custom table. So far the custom table is working well. However, the normal acf function ‘get_field’ now returns empty values for the custom fields.

    Specifically, when using Admin Columns for ACF Fields – this plugin gets the data for the admin columns via a get_field request – and this is now returning empty values. Is there a way I can filter the get_field function, check if the field_group is using a custom table, and then use get_custom_table_field if this is the case?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Abhishek

    (@abhisheksatre)

    Hi @nikkofir ,

    You can achieve this using the acf/pre_load_value filter. Copy the following code into your functions.php file.

    add_filter('acf/pre_load_value', function($value, $post_id = false, $field = array()) {

    if (!is_admin()) {
    return $value;
    }

    $screen = get_current_screen();
    if ($screen && isset($screen->base) && $screen->base === 'edit') {
    $acfFieldName = 'product_name'; // <-- Change this to the field name you want to replace
    if ($field['name'] === $acfFieldName) {
    return get_custom_table_field("wp_products", "product_name", $post_id);
    }
    }

    return $value;
    }, 10, 3);
    Thread Starter nikkofir

    (@nikkofir)

    Hi Abhishek,

    Thanks for the response – I will test and update this thread.

    Best regards,

    Tim

    Thread Starter nikkofir

    (@nikkofir)

    This is working well – thanks. I made a change to allow for all of a table’s fields to be checked.

    add_filter('acf/pre_load_value', function($value, $post_id = false, $field = array()) {

    if (!is_admin()) {
    return $value;
    }

    $screen = get_current_screen();
    if ($screen && isset($screen->base) && $screen->base === 'edit') {
    $tableFields = array('field1','field2','etc'); // <-- replace with array of column names in the custom table
    if (in_array($field['name'],$tableFields )) {
    return get_custom_table_field("CUSTOM_TABLE_NAME", $field['name'], $post_id); // <-- replace with name of custom table
    }
    }

    return $value;

    }, 10, 3);
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.