Templates for a table
-
Hi peeps,
I’m currently working on a project with the plugin. I faced the issue of having multiple posts with all the same data as template. In the current version it’s not possible to create templates without extending it. That’s why I’m making this Topic.
I made a solution and wanted to share it for the people who need a template, it’s working based on the option page, from there it is possible to setup a template.
add_filter('acf/prepare_field/key=field_xxxxxxxxxxxxx', function ($field) { global $pagenow; if($_GET['page'] !== 'general-settings' && $pagenow === 'post-new.php') { $field['value'] = json_encode(get_field('field_option', 'option', false)); } return $field; });
To prepare the field, I added the prepare_field filter:
https://www.advancedcustomfields.com/resources/acf-prepare_field/
For the field key, im using the field that I want to have prefilled.The
global $pagenow
looks if the current page is a “new” post.
The$_GET['page']
checks if current admin page is not my option page.To overwrite the empty value, it’s needed to retrieve the option page data unformatted from the database, this could be done by adding a suffix after the post_id/’option’.
After retrieving the option field you’ll have to encode the array as JSON object and overwrite the $field[‘value’] with the JSON object.
- The topic ‘Templates for a table’ is closed to new replies.