1

I created box meta for a custom post type. From the admin edit for the post, I want to enter in multiple values so that it saves as an array so I can then call it as an array from the front end.

So in my meta box from the admin edit I'd save the values "200", "201", "202" in a single field "_parent_id" and then grab it from the front end

$array = get_post_meta($postID, "_parent_id", false);

How should those values look in the box meta field?

1 Answer 1

0

Just save the array to post meta as you save string-

$data = array("200", "201", "202");

//Update inserts a new entry if it doesn't exist, updates otherwise
update_post_meta($post_ID, '_parent_id', $data);

The for getting the post call get_post_meta like below-

get_post_meta($post_ID, '_parent_id', true);

You'll get the array. Then run for or foreach loop to show the array data as you want to show.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.