php - update_post_meta on multi-dimensional array options

When updating the database, I use update_post_meta($employee->ID, '_email_address', $record->email); and

When updating the database, I use update_post_meta($employee->ID, '_email_address', $record->email); and update this result:

object(stdClass)[1295]
  public 'email' => string '[email protected]' (length=32)

How does one target an inner array for files such as leadership, profile?

object(stdClass)[1295]
 public 'biography' => string '' (length=0)
 public 'files' => 
    object(stdClass)[1294]
      public 'leadership' => null
      public 'profile' => null
      public 'blog' => null
      public 'thumbnail' => null

When updating the database, I use update_post_meta($employee->ID, '_email_address', $record->email); and update this result:

object(stdClass)[1295]
  public 'email' => string '[email protected]' (length=32)

How does one target an inner array for files such as leadership, profile?

object(stdClass)[1295]
 public 'biography' => string '' (length=0)
 public 'files' => 
    object(stdClass)[1294]
      public 'leadership' => null
      public 'profile' => null
      public 'blog' => null
      public 'thumbnail' => null
Share Improve this question asked Oct 29, 2019 at 20:27 DevSemDevSem 2092 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You can't, get_post_meta and its associated APIs all work on key/value pairs, you can update the value, but you can't update a sub-section of it. You have to retrieve the entire value, modify it, then put it back as a whole.

Additionally, values are always strings, so to make this work WordPress will PHP serialize your data, introducing a raft of security attack vectors ( object deserialisation attacks for example ). Your post meta value is also very difficult to search for.

Instead, avoid this and all the problems associated by using multiple key/value pairs instead of serialising data into a single key/value pair. Remember, you can have several post meta key/values with the same key, keys aren't unique!

And if you must store multidimensional data in a serialised format, use JSON instead. Don't rely on WP to flatten out your objects and arrays into strings

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745044250a4607996.html

相关推荐

  • php - update_post_meta on multi-dimensional array options

    When updating the database, I use update_post_meta($employee->ID, '_email_address', $record->email); and

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信