[wp-hackers] Order posts by time of their last comment
otto at ottodestruct.com
Tue Sep 28 22:12:20 UTC 2010
On Tue, Sep 28, 2010 at 4:50 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> On Sep 28, 2010, at 10:25 AM, Christian Foster wrote:
>> I am not sure of the consequence of ordering a large number of items
>> but in the docs it down mention you can sort using a numerical value
>> in a post meta key - orderby=meta_value_num. I haven't looked through
>> the code as yet to see what difference it makes.
> There's no difference in the way WordPress stores meta_values when "orderby=meta_value_num" vs. when "orderby=meta_value"; WordPress just adds a 0 to meta_value. In a nutshell it just does this:
> SELECT post_id FROM wp_postmeta ORDER BY meta_value+0
This trick basically makes MySQL treat the values as numbers instead
of as strings.
ORDER BY meta_value: 200 comes before 40.
ORDER BY meta_value+0: 40 comes before 200.
The storage is the same. The ordering is not.
More information about the wp-hackers