I am struggling with this problem. I have a group pf ACF fields and a XML file with the corresponding values. What I want is the user to be able to fill one field (with an id) and on the Publish post, to populate the values for the other fields based on the id. I am able to do the searching on the XML and fill the values, but I don't know how to run this function. I tried with 'save_post' hook but it runs the function before the publish and the id field is still empty. Any ideas how to run a function with a value from a custom field and the post id as vars?
I have this code:
function test_read($post_id) {
$file = glob('wp-content/test_folder/*.{xml}', GLOB_BRACE);
$new_ar = [];
foreach($file as $xml){
push_array($new_ar, $xml->name);
}
$value_str = $new_ar[0] .
update_post_meta($post_id, 'acf_test', $value_str );
}
add_action('save_post', 'test_read');
It seems that I am not able even to navigate through the folder. What am I doing wrong? Thank you
I am struggling with this problem. I have a group pf ACF fields and a XML file with the corresponding values. What I want is the user to be able to fill one field (with an id) and on the Publish post, to populate the values for the other fields based on the id. I am able to do the searching on the XML and fill the values, but I don't know how to run this function. I tried with 'save_post' hook but it runs the function before the publish and the id field is still empty. Any ideas how to run a function with a value from a custom field and the post id as vars?
I have this code:
function test_read($post_id) {
$file = glob('wp-content/test_folder/*.{xml}', GLOB_BRACE);
$new_ar = [];
foreach($file as $xml){
push_array($new_ar, $xml->name);
}
$value_str = $new_ar[0] .
update_post_meta($post_id, 'acf_test', $value_str );
}
add_action('save_post', 'test_read');
It seems that I am not able even to navigate through the folder. What am I doing wrong? Thank you
Share Improve this question edited Dec 5, 2020 at 22:02 marissalianam asked Dec 5, 2020 at 17:21 marissalianammarissalianam 211 silver badge3 bronze badges1 Answer
Reset to default 0Untested, but if I understand you correctly, try something like this:
$results = new WP_Query( array (
'post_id' => '<id-here>',
'post_type' => 'acf-field', //not necessary, but insurance
'post_excerpt' => '<custom-field-name>', //not necessary, but insurance
'meta_query' => array (
'key' => '<custom-field-name>',
)
)
);