WordPress.org

Support

Support » Plugins and Hacks » PostgreSQL for WordPress (PG4WP) » WP_Query Order By Meta_Value_Num

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 the driver_pgsql.php file. 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.php at 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 PgSQL cast() function.

    Hopefully this will help someone else who’s struggling with this in the future.

    http://wordpress.org/extend/plugins/postgresql-for-wordpress/

  • The topic ‘WP_Query Order By Meta_Value_Num’ is closed to new replies.
Skip to toolbar