Skip to main content
deleted 99 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

Post meta values are strings/text, any internal structure suchYou would do it the same way as arrays or sub-arrays is purely contextual and impliedany other PHP application, and generally notthis isn't a good idea, especially if you want to sort/filter/query for those sub-valuesWordPress problem.

So you can't make WordPress itself update just the sub-section you wantTo remove an item from an array in PHP, use unset( thing to remove ).

Instead, you have to retrieve the entire meta value, change it, then put the entire thing backE. There's no such thing as "sub-updates"g.

$test = [ 'banana', 'cucumber', 'apple' ];
unset( $test[1] );
// cucumber is no longer in the test array, and the array now has 2 not 3 items

Post meta values are strings/text, any internal structure such as arrays or sub-arrays is purely contextual and implied, and generally not a good idea, especially if you want to sort/filter/query for those sub-values.

So you can't make WordPress itself update just the sub-section you want.

Instead, you have to retrieve the entire meta value, change it, then put the entire thing back. There's no such thing as "sub-updates".

You would do it the same way as any other PHP application, this isn't a WordPress problem.

To remove an item from an array in PHP, use unset( thing to remove ).

E.g.

$test = [ 'banana', 'cucumber', 'apple' ];
unset( $test[1] );
// cucumber is no longer in the test array, and the array now has 2 not 3 items
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

Post meta values are strings/text, any internal structure such as arrays or sub-arrays is purely contextual and implied, and generally not a good idea, especially if you want to sort/filter/query for those sub-values.

So you can't make WordPress itself update just the sub-section you want.

Instead, you have to retrieve the entire meta value, change it, then put the entire thing back. There's no such thing as "sub-updates".