Adding custom image fields and other fields at the same time

前端 未结 3 1660
粉色の甜心
粉色の甜心 2020-12-01 17:55

I basically want to have a custom CMS page that has pairs of images and labels for those images defined within it. I intend to use these pairs of items for populating conte

3条回答
  •  长情又很酷
    2020-12-01 18:11

    You don't exactly mention it, but it seems that you are dealing with Repeatable Fields.

    Two plugins of interest: Advanced Custom Fields and Custom Content Type Manager.

    Today, I've seen this article in one of WordPress communities at G+:
    Using the WordPress 3.5 Media Uploader within plugins.

    This solution was originally published here in a SO Question that has been deleted since. It is rewritten, revised and tested:

    ID, 'gallery_data', true );
    
        // Use nonce for verification
        wp_nonce_field( plugin_basename( __FILE__ ), 'noncename_so_14445904' );
    ?>
    
    

    post_type ) return; ?> post_type ) return; // Verify authenticity if ( !wp_verify_nonce( $_POST['noncename_so_14445904'], plugin_basename( __FILE__ ) ) ) return; // Correct post type if ( 'post' != $_POST['post_type'] ) return; if ( $_POST['gallery'] ) { // Build array for saving post meta $gallery_data = array(); for ($i = 0; $i < count( $_POST['gallery']['image_url'] ); $i++ ) { if ( '' != $_POST['gallery']['image_url'][ $i ] ) { $gallery_data['image_url'][] = $_POST['gallery']['image_url'][ $i ]; $gallery_data['image_desc'][] = $_POST['gallery']['image_desc'][ $i ]; } } if ( $gallery_data ) update_post_meta( $post_id, 'gallery_data', $gallery_data ); else delete_post_meta( $post_id, 'gallery_data' ); } // Nothing received, all fields are empty, delete option else { delete_post_meta( $post_id, 'gallery_data' ); } }

    Result:
    repeatable uploader

提交回复
热议问题