最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

save post - Use value from ACF to populate other fields

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Untested, 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>',
        )
    )
);
发布评论

评论列表(0)

  1. 暂无评论