[wp-trac] [WordPress Trac] #60950: JSON serialization for meta values
WordPress Trac
noreply at wordpress.org
Wed May 8 17:52:34 UTC 2024
#60950: JSON serialization for meta values
--------------------------------+------------------------------
Reporter: inf3rno | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version:
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses: performance
--------------------------------+------------------------------
Comment (by inf3rno):
@johnbillion
I don't think I am the best person to decide about API changes or
implementation, but ok.
Well it is a general concept, you can use any time you have multiple meta
keys to group them and reduce database bloating. Currently I am not
working on a project, but it is not a rare situation to have a single
query with multiple meta keys. In all of those cases the keys could be
grouped into a single JSON instead of storing them separately.
E.g. a delivery post type which contains an address and we query the city
and the street, maybe we are in the delivery truck and we need addresses
close to our location to plan our route.
Afaik. with the current API the meta query looks like this:
{{{#!php
<?php
$arg['meta_query'] = [
'relation' => 'AND',
[
'key' => 'city',
'value' => 'New York',
'compare' => '='
],
[
'key' => 'street',
'value' => 'Broadway',
'compare' => '='
]
];
}}}
Storage:
{{{
meta_key | meta_value
address_city | s:8:"New York";
address_street | s:8:"Broadway";
address_number | s:3:"128";,
package_id | s:3:"345";
}}}
With the JSON API we can use nested keys and reduce the number of meta
keys:
{{{#!php
<?php
$arg['meta_query'] = [
'relation' => 'AND',
[
'key' => ['address','city'],
'value' => 'New York',
'compare' => '='
],
[
'key' => ['address','street'],
'value' => 'Broadway',
'compare' => '='
]
];
}}}
Storage:
{{{
meta_key | meta_format | meta_value
address | JSON | {"city": "New York", "street": "Broadway",
"number": 128}
package_id | PHP | s:3:"345";
}}}
I guess it could be solved this way.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60950#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list