Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tectureben opened this issue Mar 21, 2024 · 0 comments

Comments

@tectureben
Copy link

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant