[wp-hackers] Meta boxes and post metadata

Otto otto at ottodestruct.com
Fri Feb 22 23:38:17 UTC 2013


"Doing it wrong" can be subjective. If I was him, I'd store all the
relevant meta information in a single array, then store that array in
a single meta-key.

The question of whether you store empty data vs. not have the data, or
even whether you store data in an array form (which means it's
serialized) comes down to what you are using the data for, and in what
way you are using it.

For a case where you're never searching on that meta-data or ordering
by it, or using it in any other way except to perhaps display it
somewhere, then the single meta entry makes more sense. The idea being
that every case where you get the data, you're going to get all of it,
and only display it.

If you need to sort by it in some fashion, or search based on it, then
obviously storing it with its own key and in a non-serialized form
makes the most sense. These sorts of things happen in SQL, and the SQL
language does not understand serialized data.

As for empty vs. non-existent, there can be a difference between the
two, so which is correct depends on your particular use case and
whether or not there is a tangible difference in the behavior. Mostly,
I doubt it matters that often.

As for number of rows, that shouldn't be your primary concern. If you
start reaching a point where table sizes grow too big, then you should
start optimizing the database structure itself in mySQL, outside of
the web application level. Additional servers, dedicated servers, that
sort of thing. You cannot run a million posts on a cheap shared
database server, no matter how much the client might want to. Consult
a qualified DBA.

-Otto


On Fri, Feb 22, 2013 at 5:30 PM, Radi Varbanov <aparoph at gmail.com> wrote:
> Is Yoast doing it wrong?
>
> Is there a situation when you need to store empty meta_value?
>
> Thx,
> Radi
>
>
> On Thu, Feb 21, 2013 at 7:01 AM, Alexander Höreth <a.hoereth at gmail.com>wrote:
>
>> Same here: Only create DB entries when they contain information.
>> Use "not existing" equal to "empty" => if empty, delete.
>>
>> Alex
>>
>>
>> 2013/2/21 Steve Taylor <steve at sltaylor.co.uk>
>>
>> > A plugin I do (
>> > http://wordpress.org/extend/plugins/developers-custom-fields/)
>> > used to create DB records even if nothing was entered into the custom
>> > field. I changed it to not create a record if the value is empty, also
>> > to delete the existing record if it exists, but the new value entered
>> > is empty.
>> >
>> > No problems so far - I think in retrieving values you get the same
>> > result from an empty record as from no record.
>> >
>> > I'd be interested to hear if anyone else has alternate views on this.
>> >
>> > Cheers,
>> >
>> > Steve
>> >
>> >
>> > On 20 February 2013 16:05, Radi Varbanov <aparoph at gmail.com> wrote:
>> > > Hi Everyone,
>> > > First time posting here, so please bare with me :)
>> > >
>> > > I am working on a site that is using the Yoast wpseo plugin and noticed
>> > > that even if you leave the SEO fields empty the plugin will store an
>> > empty
>> > > row into the wp_postmeta table. That made me think about how I should
>> use
>> > > meta boxes.
>> > >
>> > > So my question is:
>> > > When I use custom meta boxes should I also insert empty rows into the
>> > > wp_postmeta table or I should check to see if the fields is empty and
>> if
>> > it
>> > > is, do not store anything? With small websites that my be not a problem
>> > but
>> > > when you have 50k+ posts and have ~10 custom post meta boxes and 11
>> form
>> > > the SEO plugin that adds up very fast.
>> > >
>> > > Thanks,
>> > > Radi.
>> > > _______________________________________________
>> > > wp-hackers mailing list
>> > > wp-hackers at lists.automattic.com
>> > > http://lists.automattic.com/mailman/listinfo/wp-hackers
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list