lundi 29 février 2016

Pods 2.x orderby plain number (numerical order, not alpha)

Does anyone know how to force the WP Pods plugin to correctly sort records in numerical order? The field I'm sorting by is a "Plain Number" field, but the following code yields records sorted alphabetically (i.e. 1, 10, 11, 12, 13, 2, 3, 4, etc.):

$params = array(
    'where' => "work.ID = '".$rep_id."'",
    'orderby' => 'sortnum ASC',
);
$pod_role = pods('repertoire_role', $params );

while ( $pod_role->fetch() ) {
    $roles[] = array('ID' => $pod_role->field('ID'), 'role' => $pod_role->field('role') );
}

I tried using additional parameters as in a WP_Query, e.g.:

'orderby'   => 'meta_value_num',
'meta_key'  => 'sortnum',

And also tried:

'orderby' => 'sortnum ASC',
'meta_type' => 'NUMERIC'

...but the first of those resulted in SQL errors and the second had no effect at all. Any help would be much appreciated!

By the way, has anyone else had issues with the Pods website forum? I tried to log in using both Google+ and Wordpress.com credentials, but the first resulted in an error message, and the second appeared to work at first but then redirected me to the login form....



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire