Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ACF get_field()返回空_Php_Wordpress_Advanced Custom Fields - Fatal编程技术网

Php ACF get_field()返回空

Php ACF get_field()返回空,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我正在开发一个应用程序,使用ACF插件,通过自定义文章类型和自定义字段。保存自定义帖子类型时,它将在“我的网络”中创建一个博客,效果非常好。但是,当尝试使用相同的acf自定义字段将自定义字段从自定义帖子类型复制到新创建的博客主页时,不会保存acf自定义字段 我测试过,$station\u description='notempty'并且它确实可以毫无问题地保存/复制到其特定字段。只是当我使用get_field()时,它不会保存/复制到新创建的博客 我的代码怎么了 function myy_acf

我正在开发一个应用程序,使用ACF插件,通过自定义文章类型和自定义字段。保存自定义帖子类型时,它将在“我的网络”中创建一个博客,效果非常好。但是,当尝试使用相同的acf自定义字段将自定义字段从自定义帖子类型复制到新创建的博客主页时,不会保存acf自定义字段

我测试过,
$station\u description='notempty'并且它确实可以毫无问题地保存/复制到其特定字段。只是当我使用get_field()时,它不会保存/复制到新创建的博客

我的代码怎么了

function myy_acf_save_post( $post_id ) {
    $post = get_post($post_id);   

    if( $post->post_type == 'network_directory' ) {

    $title = $post->post_title;
    $post_slug = $post->post_name;
    $client_username = get_field('client_username', $post_id);
    $station_server = get_field('station_server', $post_id);
    $station_location = get_field('station_location', $post_id);
    // $station_description = get_field('station_description', $post_id);
    $station_description = 'Not Empty';
    $language = get_field('language', $post_id);
    $station_email = get_field('station_email', $post_id);
    $station_website = get_field('station_website', $post_id);
    $station_port = get_field('station_port', $post_id);
    $station_logo = get_field('station_logo', $post_id);
    // $station_logo_url = wp_get_attachment_url( $station_logo );
    // $subdomain = get_field('subdomain', $post->ID);

    $main_site = 'domain.com';

    $subdomain_install = true;

    # Create a new user
    $check_user_id = get_user_id_from_string( $station_email );
    if ($check_user_id !== null) {
        $user_id = get_user_id_from_string( $station_email );
    } else {
        $rand_number = rand( 1, 2000 );
        $username = 'user-' . $rand_number;
        $password = wp_generate_password( 12, false );
        $email = $station_email;
        $user_id = wpmu_create_user( $username, $password, $email );
    }
    // wp_new_user_notification( $user_id, $password );

    # Create site
    if( $subdomain_install )
    {
        $newdomain = "{$post_slug}.$main_site";
        $path = '/';
    }

    $the_blog_id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ) );


            if ( ! add_post_meta( $post_id, 'blog_id_meta_key', $the_blog_id, true ) ) { 
                update_post_meta( $post_id, 'blog_id_meta_key', $the_blog_id );
            }

            switch_to_blog( $the_blog_id );
                $homepage_id = get_option( 'page_on_front' );
                // $station_logo_new_src = media_sideload_image($station_logo_url, $homepage_id, 'Station Logo','src');
                // $station_logo_new_id = get_attachment_id_from_src($station_logo_new_src);
                update_field('client_username', $client_username, $homepage_id);
                update_field('station_server', $station_server, $homepage_id);
                update_field('station_location', $station_location, $homepage_id);
                update_field('language', $language, $homepage_id);
                update_field('station_email', $station_email, $homepage_id);
                update_field('station_website', $station_website, $homepage_id);
                update_field('station_port', $station_port, $homepage_id);
                // update_field('station_logo', $station_logo_new_id, $homepage_id);
                update_field('station_description', $station_description, $homepage_id);
            restore_current_blog();



    }   

}

add_action('acf/save_post', 'myy_acf_save_post', 9999);
说吧


使用
get\u post\u meta
检索值比
get\u field
抛出
print\r(模板中的get\u post\u meta(get\u the\u ID())
将输出可用的字段,这对调试非常有用。在我的例子中,在对页面上的模块重新排序后,我注意到
get\u post\u meta
输出出乎意料,这帮助我看到我忘记了使用
wp\u reset\u postdata()

重置页面上方的查询。请澄清一下?您是否找到了使用get_post_meta()检索字段内容的方法?