Skip to main content
11 events
when toggle format what by license comment
Mar 8, 2022 at 15:03 comment added Gildas.Tambo Let us continue this discussion in chat.
Mar 8, 2022 at 15:03 comment added Tom J Nowell you mean you can remove items from the meta, but you cannot empty the entire thing? That was not obvious from your question ( I'm still not sure I have the right understanding). This isn't very clear
Mar 8, 2022 at 15:00 comment added Gildas.Tambo yes it is correct since i can update it delete it but not empty it meaning when i have 4items in it and just delete 3 it works fine but not if i delete all 4items. And that is where i am currently stuck
Mar 8, 2022 at 14:57 comment added Tom J Nowell Also $_POST['meta']['ds_product_gallery'] is a weird thing to see, are you absolutely sure that is correct? And have you verified that the update meta call is actually happening? Not a "it should be" but an "I saw output that can only happen inside that else statement" or a pause on a debugger?
Mar 8, 2022 at 14:54 comment added Tom J Nowell Here's the relevant doc: php.net/manual/en/function.unset.php, as I said, this isn't a WordPress problem, it's a generic PHP problem. If your meta still has the values you tried to remove, it's because you did not remove them successfully. Either that or the code you're trying to debug is never run to begin with
Mar 8, 2022 at 14:54 comment added Tom J Nowell you update the meta by grabbing its value, changing that value, then updating it, you've already figured out that part
Mar 8, 2022 at 14:53 comment added Gildas.Tambo ok mate, but how do you update the meta then? i tried $data = get_post_meta( $post->ID, 'meta', true ); unset($data['ds_product_gallery']); update_post_meta( $post_ID, 'meta', $data ); but nothing
Mar 8, 2022 at 14:53 history edited Tom J Nowell CC BY-SA 4.0
deleted 99 characters in body
Mar 8, 2022 at 14:51 comment added Tom J Nowell $data['ds_product_gallery'][0][0] = []; sets it to an empty array, if you want to remove the item from the array though then that's a general PHP problem not a WordPress problem, you can rephrase this question as "How do I remove an item from an array", use unset().
Mar 8, 2022 at 14:48 comment added Gildas.Tambo have a look at the else section that is exactly what i am doing but it doesn't work i even tried $data = get_post_meta( $post->ID, 'meta', true ); $data['ds_product_gallery'] = []; update_post_meta( $post_ID, 'meta', $data ); without success
Mar 8, 2022 at 14:43 history answered Tom J Nowell CC BY-SA 4.0