Pods: orderby on plain number field orders incorrectly

Created on 25 Dec 2012  路  9Comments  路  Source: pods-framework/pods

I have a plain number field (decimals 0, max. length 4) set up to order my pods (products) but if I use 'orderby' => 'product_weight DESC' the order returned is incorrect. The sequence returned is shown below:

980, 970, 90, 890, 880, ... 810, 800, 80, 790, ... 120, 110, 1000, 100, -130, -120, -110

How can I order the pods in a user chosen sequence? or order correctly by number?

Out of scope

Most helpful comment

If your Pod is meta-based, you should be using:

'orderby' => 'product_page_weight.meta_value DESC'

And if you want it to count as an integer (sorry, WordPress stores all meta values as DB LONGTEXT which is just text) you will have to use:

'orderby' => 'CAST( product_page_weight.meta_value AS SIGNED ) DESC'

Even WordPress acknowledges this and has options that do the same thing in their WP_Query functionality, listed under the meta_query 'type' option:

http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

All 9 comments

Can you screenshot or tell us what your field settings are for this field in your Pod?

Also, what type of Pod is it? Advanced Content Type, Post Type, Taxonomy, Media, User, Comment? And what storage type? Table or Meta?

This is common i have found.. If you add 0900 it will come before 1000 .. without that leading 0 it sees 9 as coming before 1 and ignores how many digits in there

Is this a Plain Text field or Plain Number? Pods stores these numbers correctly, so it doesn't have to change how it orders, it uses MySQL ordering for that since it's a integer / decimal field.

Thanks for looking at the problem.

The field type is 'plain number' not plain text.
Pods type 'custom post type'
Meta storage

I have tried padding with zeros (0900, 0910 etc.) but the leading zero is removed after the field has been submitted.

And paste the exact code you're using please

Trying to use 'product_page_weight' to order the products on the page so the higher the number the higher up the page
1000
990
980
etc.

$params = array(
'limit' => -1,
//'where' => 'wp_terms.slug = "animals"',
'orderby' => 'product_page_weight DESC',
);
$pods = pods('products');
$pods->find($params);

if ($pods->total() > 0) {
while ($pods->fetch()) {

... output pod details here ...

}

}

If your Pod is meta-based, you should be using:

'orderby' => 'product_page_weight.meta_value DESC'

And if you want it to count as an integer (sorry, WordPress stores all meta values as DB LONGTEXT which is just text) you will have to use:

'orderby' => 'CAST( product_page_weight.meta_value AS SIGNED ) DESC'

Even WordPress acknowledges this and has options that do the same thing in their WP_Query functionality, listed under the meta_query 'type' option:

http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

Just found out about this after 3 hours of testing as I switched from advanced custom type pod to custom post type.

As far as I understand this is a WordPress problem, otherwise I think that needs to be improved within Pods.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kpudlo picture Kpudlo  路  4Comments

qx54 picture qx54  路  4Comments

devont3 picture devont3  路  3Comments

jnaklaas picture jnaklaas  路  3Comments

Ramoonus picture Ramoonus  路  5Comments