Skip to content

Import into dropdown custom metabox fields results in serialized array #3

Open
@tectureben

Description

@tectureben

I've created a post type with some dropdown fields. One for user, one referencing another post type (user and post field types).

image

Here is an example of how I'm mapping the ids from my source file using WPAI with the extension:

image

My observation is that the id is saved as a serialized array into postmeta. When I go into the UI and click save, it saves as numbers and eliminates the array.

I have worked around this issue by hooking into pmxi_saved_post.

add_action( 'pmxi_saved_post', function( $post_id, $xml_node, $is_update ) {

	$user = get_post_meta( $post_id, 'user_field', true );
	$post = get_post_meta( $post_id, 'post_field', true );

	if (is_array($user)) {
		$user = $user[0];
		rwmb_set_meta( $post_id, 'user_field', $user );
	}
	
	if (is_array($post)) {
		$related = $related[0];
		rwmb_set_meta( $post_id, 'post_field', $related );
	}

}, 10, 3);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions