【问题标题】:Saving Wordpress Custom Meta Info保存 Wordpress 自定义元信息
【发布时间】:2015-06-23 23:27:28
【问题描述】:

nwt_home_section_header_io我用来保存自定义元框的代码根本不起作用,你能告诉我哪里出错了吗?目前它只保存一个单选按钮,因此数组中只有一个条目。

谢谢

function save_nwt_home_section_settings_meta($post_id, $post) {
    // Is the user allowed to edit the post or page?
    if ( !current_user_can( 'edit_post', $post->ID ))
        return $post->ID;

    // OK, we're authenticated: we need to find and save the data
    // We'll put it into an array to make it easier to loop though.

    $nwt_home_section_settings_array = array(
        'nwt_home_section_header_io' => $_POST['nwt_home_section_header_io']
    );

    // Add values of $events_meta as custom fields
    foreach ($nwt_home_section_settings_array as $key => $value) { // Cycle through the $events_meta array!

        if( $post->post_type == 'revision' ) return; // Don't store custom data twice

            update_post_meta($post->ID, $key, $value);

        if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
    }
}

add_action('save_post', 'save_nwt_home_section_settings_meta', 1, 2); // save the custom fields

【问题讨论】:

    标签: php wordpress radio-button


    【解决方案1】:
    Please try somthing like this
    
    $resources = $_POST['authors-commentary-resources'];
        $sanitized_resources = array();
        foreach ( $resources as $resource ) {
    
            $resource = esc_url( strip_tags( $resource ) );
            if ( ! empty( $resource ) ) {
                $sanitized_resources[] = $resource;
            }
    
        }
    
        update_post_meta( $post_id, 'authors-commentary-resources', $sanitized_resources );
    
    }
    

    【讨论】:

    • 对不起,但这不起作用,正如您从编辑的代码(更易于阅读)中看到的那样,我基本上正在按照您的建议进行操作,但是通过循环遍历数组来动态执行此操作。我也尝试将键和值添加为字符串,但它仍然无法保存
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 2016-12-31
    • 2016-03-26
    • 1970-01-01
    • 2012-11-23
    • 2017-01-12
    • 1970-01-01
    相关资源
    最近更新 更多