WP_Query Order By Meta_Value_Num
-
For those using a WP_Query to order posts by a custom meta_value (numerically, using
'orderby' => 'meta_value_num'), you will have to make a change to thedriver_pgsql.phpfile. Because WordPress creates a query casting the string to an integer (that only works in MySQL), this has to be rewritten for PgSQL.To do this, in
driver_pgsql.phpat line 288, add:if(preg_match('/wp_postmeta\.meta_value\+0/', $sql)) $sql = str_replace('wp_postmeta.meta_value+0', 'cast(wp_postmeta.meta_value as int)', $sql);This converts the MySQL cast (the
+0) to the PgSQLcast()function.Hopefully this will help someone else who’s struggling with this in the future.
The topic ‘WP_Query Order By Meta_Value_Num’ is closed to new replies.