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
1 Answer
Reset to default 2You 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
评论列表(0条)