<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A better meta API for WordPress</title>
	<atom:link href="http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/</link>
	<description>Random commentary...</description>
	<lastBuildDate>Wed, 17 Feb 2010 21:07:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<item>
		<title>By: westi</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-210062</link>
		<dc:creator>westi</dc:creator>
		<pubDate>Sun, 09 Aug 2009 14:11:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-210062</guid>
		<description>Yes we need to get the storage correct.

My point was the most important thing is the API - if we get that wrong it&#039;s much harder to change.

Making incremental changes to the db structure to optimise it when issues arise is much easier that fixing a broken API :-)</description>
		<content:encoded><![CDATA[<p>Yes we need to get the storage correct.</p>
<p>My point was the most important thing is the API &#8211; if we get that wrong it&#8217;s much harder to change.</p>
<p>Making incremental changes to the db structure to optimise it when issues arise is much easier that fixing a broken API <img src='http://blog.ftwr.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: westi</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-210061</link>
		<dc:creator>westi</dc:creator>
		<pubDate>Sun, 09 Aug 2009 14:09:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-210061</guid>
		<description>The idea here was to make it possible to query the meta data in appropriate ways.

I don&#039;t have any specific examples - but the aim would be to ensure that plugins can avoid direct queries.</description>
		<content:encoded><![CDATA[<p>The idea here was to make it possible to query the meta data in appropriate ways.</p>
<p>I don&#8217;t have any specific examples &#8211; but the aim would be to ensure that plugins can avoid direct queries.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scribu</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-208059</link>
		<dc:creator>scribu</dc:creator>
		<pubDate>Sun, 26 Jul 2009 00:07:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-208059</guid>
		<description>I&#039;ve submitted a basic patch to &lt;a href=&quot;http://core.trac.wordpress.org/ticket/10487&quot; rel=&quot;nofollow&quot;&gt;#10487&lt;/a&gt;.

I would like to know what you had in mind with $search_type in

get_meta_values(&#039;cron&#039;, $search_value, $search_type);</description>
		<content:encoded><![CDATA[<p>I&#8217;ve submitted a basic patch to <a href="http://core.trac.wordpress.org/ticket/10487" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/core.trac.wordpress.org/ticket/10487?referer=');">#10487</a>.</p>
<p>I would like to know what you had in mind with $search_type in</p>
<p>get_meta_values(&#8216;cron&#8217;, $search_value, $search_type);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Schinkel</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-207924</link>
		<dc:creator>Mike Schinkel</dc:creator>
		<pubDate>Fri, 24 Jul 2009 22:50:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-207924</guid>
		<description>@westi: &quot;If the API is good and well thought out they don’t need to care about the table structure and we can always change it later.&quot;

While in general I agree with you, strict adherence to your words could paint us into a nasty corner.  Let me use an example:  The API could be implemented to store all meta for a post as a serialized array in the wp_posts table. Doing so would adhere to your &quot;table structure doesn&#039;t matter&quot; ideal but would be disastrous for enabling additional functionality.  If meta was implemented in that manner it would be effectively impossible to implement a performant filter on a list of posts for a given meta key/value pair because every record would have to be tested via PHP instead of pushing to SQL in a WHERE clause. 

This is the exact problem I had with NexGen Gallery in that it used serialized arrays instead of a proper linking table. In order to implement functionality required by my client I had to modify the code for that plugin.

So yes, ideally a good API should be all that matters but in reality the table structure does matter.</description>
		<content:encoded><![CDATA[<p>@westi: &#8220;If the API is good and well thought out they don’t need to care about the table structure and we can always change it later.&#8221;</p>
<p>While in general I agree with you, strict adherence to your words could paint us into a nasty corner.  Let me use an example:  The API could be implemented to store all meta for a post as a serialized array in the wp_posts table. Doing so would adhere to your &#8220;table structure doesn&#8217;t matter&#8221; ideal but would be disastrous for enabling additional functionality.  If meta was implemented in that manner it would be effectively impossible to implement a performant filter on a list of posts for a given meta key/value pair because every record would have to be tested via PHP instead of pushing to SQL in a WHERE clause. </p>
<p>This is the exact problem I had with NexGen Gallery in that it used serialized arrays instead of a proper linking table. In order to implement functionality required by my client I had to modify the code for that plugin.</p>
<p>So yes, ideally a good API should be all that matters but in reality the table structure does matter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scribu</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-207891</link>
		<dc:creator>scribu</dc:creator>
		<pubDate>Fri, 24 Jul 2009 12:26:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-207891</guid>
		<description>
&lt;blockquote&gt;@scribu: Is what the plugin does really not possible we the post meta key / value stuff built into WP_Query e.g. - https://core.trac.wordpress.org/ticket/7431 and https://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L2140&lt;/blockquote&gt;

No, because it has to check for more than one key-value pair.

&lt;blockquote&gt;We should strive to provide a &lt;em&gt;good enough&lt;/em&gt; api so that plugins don&#039;t have to use direct SQL queries.&lt;/blockquote&gt;

Completely agree.

&lt;blockquote&gt;We try very hard to maintain apis we are not interested in maintaining table structures just to not break plugins.&lt;/blockquote&gt;

I know, but why break plugins unnecessarily? :)

Anyway, I&#039;m glad we agree that plugins shouldn&#039;t have to deal with creating meta tables, no matter the type.</description>
		<content:encoded><![CDATA[<blockquote><p>@scribu: Is what the plugin does really not possible we the post meta key / value stuff built into WP_Query e.g. &#8211; <a href="https://core.trac.wordpress.org/ticket/7431" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/core.trac.wordpress.org/ticket/7431?referer=');">https://core.trac.wordpress.org/ticket/7431</a> and <a href="https://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L2140" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/core.trac.wordpress.org/browser/trunk/wp-includes/query.php_L2140?referer=');">https://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L2140</a></p></blockquote>
<p>No, because it has to check for more than one key-value pair.</p>
<blockquote><p>We should strive to provide a <em>good enough</em> api so that plugins don&#8217;t have to use direct SQL queries.</p></blockquote>
<p>Completely agree.</p>
<blockquote><p>We try very hard to maintain apis we are not interested in maintaining table structures just to not break plugins.</p></blockquote>
<p>I know, but why break plugins unnecessarily? <img src='http://blog.ftwr.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyway, I&#8217;m glad we agree that plugins shouldn&#8217;t have to deal with creating meta tables, no matter the type.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: westi</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-207888</link>
		<dc:creator>westi</dc:creator>
		<pubDate>Fri, 24 Jul 2009 12:10:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-207888</guid>
		<description>@scribu: Is what the plugin does really not possible we the post meta key / value stuff built into WP_Query e.g. - https://core.trac.wordpress.org/ticket/7431 and https://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L2140

Yes.  There will always be cases which are the exception that breaks the rule.

We should strive to provide a &lt;em&gt;good enough&lt;/em&gt; api so that plugins don&#039;t have to use direct SQL queries.

We try very hard to maintain apis we are not interested in maintaining table structures just to not break plugins.</description>
		<content:encoded><![CDATA[<p>@scribu: Is what the plugin does really not possible we the post meta key / value stuff built into WP_Query e.g. &#8211; <a href="https://core.trac.wordpress.org/ticket/7431" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/core.trac.wordpress.org/ticket/7431?referer=');">https://core.trac.wordpress.org/ticket/7431</a> and <a href="https://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L2140" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/core.trac.wordpress.org/browser/trunk/wp-includes/query.php_L2140?referer=');">https://core.trac.wordpress.org/browser/trunk/wp-includes/query.php#L2140</a></p>
<p>Yes.  There will always be cases which are the exception that breaks the rule.</p>
<p>We should strive to provide a <em>good enough</em> api so that plugins don&#8217;t have to use direct SQL queries.</p>
<p>We try very hard to maintain apis we are not interested in maintaining table structures just to not break plugins.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scribu</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-207887</link>
		<dc:creator>scribu</dc:creator>
		<pubDate>Fri, 24 Jul 2009 11:52:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-207887</guid>
		<description>As a counter-example, I have a plugin that does some funky WHERE clauses to retrieve posts based on meta values. There&#039;s no way of achieving that without raw SQL.

I assume that other plugins that would be relying on comment meta, for example, would need similar functionality.</description>
		<content:encoded><![CDATA[<p>As a counter-example, I have a plugin that does some funky WHERE clauses to retrieve posts based on meta values. There&#8217;s no way of achieving that without raw SQL.</p>
<p>I assume that other plugins that would be relying on comment meta, for example, would need similar functionality.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: westi</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-207885</link>
		<dc:creator>westi</dc:creator>
		<pubDate>Fri, 24 Jul 2009 11:37:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-207885</guid>
		<description>If we design the API well enough the consumers of the api don&#039;t need to know about the table structure underneath.

If people need different ways of accessing the data then we should add API calls for it - plugins shouldn&#039;t need to use raw SQL queries to achieve things as then we lose the benefits that caching can provide.

If we have multi-table we are likely to end up with a lot of similar looking tables, if we have single table we will need an extra column for the type of meta - the only choice between the two is going to be performance.

In both cases we should be able to write an api which means that plugins don&#039;t do raw SQL queries - that way we could make it possible for people to use either approach depending on there scaling needs.  But that&#039;s all implementation detail ;-)</description>
		<content:encoded><![CDATA[<p>If we design the API well enough the consumers of the api don&#8217;t need to know about the table structure underneath.</p>
<p>If people need different ways of accessing the data then we should add API calls for it &#8211; plugins shouldn&#8217;t need to use raw SQL queries to achieve things as then we lose the benefits that caching can provide.</p>
<p>If we have multi-table we are likely to end up with a lot of similar looking tables, if we have single table we will need an extra column for the type of meta &#8211; the only choice between the two is going to be performance.</p>
<p>In both cases we should be able to write an api which means that plugins don&#8217;t do raw SQL queries &#8211; that way we could make it possible for people to use either approach depending on there scaling needs.  But that&#8217;s all implementation detail <img src='http://blog.ftwr.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: westi</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-207877</link>
		<dc:creator>westi</dc:creator>
		<pubDate>Fri, 24 Jul 2009 07:45:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-207877</guid>
		<description>Very true,  something I had missed out on in this is an associated object_id for the meta entries when they are directly associated like post, comment and attachment meta would be.</description>
		<content:encoded><![CDATA[<p>Very true,  something I had missed out on in this is an associated object_id for the meta entries when they are directly associated like post, comment and attachment meta would be.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Beau lebens</title>
		<link>http://blog.ftwr.co.uk/archives/2009/07/23/a-better-meta-api-for-wordpress/comment-page-1/#comment-207853</link>
		<dc:creator>Beau lebens</dc:creator>
		<pubDate>Fri, 24 Jul 2009 01:48:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.ftwr.co.uk/?p=334#comment-207853</guid>
		<description>If that was used to replace something like postmeta, then wouldn&#039;t you want some sort of meta_type_id in there as well? e.g. so that you could get the key=&#039;post_custom_field_name&#039;, that belongs to a specific post? You could just add it on like this:

get_meta_value( &#039;post&#039;, &#039;post_custom_field_name&#039;, 123 );

putting the meta_type_id last would allow you to make it optional easily, so that for something like your example (cron) where you might not have a numeric id that makes sense, it could be automatically handled (or completely ignored) internally. That would allow you to index the tables on that value, speeding up lookups a lot (since if we stick all meta in one big table, it&#039;s going to get pretty big, pretty quickly).</description>
		<content:encoded><![CDATA[<p>If that was used to replace something like postmeta, then wouldn&#8217;t you want some sort of meta_type_id in there as well? e.g. so that you could get the key=&#8217;post_custom_field_name&#8217;, that belongs to a specific post? You could just add it on like this:</p>
<p>get_meta_value( &#8216;post&#8217;, &#8216;post_custom_field_name&#8217;, 123 );</p>
<p>putting the meta_type_id last would allow you to make it optional easily, so that for something like your example (cron) where you might not have a numeric id that makes sense, it could be automatically handled (or completely ignored) internally. That would allow you to index the tables on that value, speeding up lookups a lot (since if we stick all meta in one big table, it&#8217;s going to get pretty big, pretty quickly).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
