最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Sorting meta_value as integer doesn't work

programmeradmin2浏览0评论

This plugin uses the below chunk of code to print the top 10 highscores.

But this doesn't get the list of top 10 scores sorted by meta_value in my WP install

$scoreboard = new WP_User_Query( array(
    'number'       => $top,
    'exclude'      => array( $exclude ),
    'orderby'      => 'meta_value',
    'order'        => 'DESC',
    'meta_key'     => 'wp2048_score',
    'meta_value'   => '0',
    'meta_compare' => '>',
) );

what could be wrong? I tried using meta_value_num too for orderby but still won't work. Am on wordpress 3.9.1

This plugin uses the below chunk of code to print the top 10 highscores.

But this doesn't get the list of top 10 scores sorted by meta_value in my WP install

$scoreboard = new WP_User_Query( array(
    'number'       => $top,
    'exclude'      => array( $exclude ),
    'orderby'      => 'meta_value',
    'order'        => 'DESC',
    'meta_key'     => 'wp2048_score',
    'meta_value'   => '0',
    'meta_compare' => '>',
) );

what could be wrong? I tried using meta_value_num too for orderby but still won't work. Am on wordpress 3.9.1

Share Improve this question edited Jul 22, 2014 at 9:05 kaiser 50.9k27 gold badges151 silver badges245 bronze badges asked Jul 21, 2014 at 18:11 Man_PatMan_Pat 11 bronze badge 4
  • Please inent and add your code properly next time, it is unreadable. Also, contact the plugin author about this matter. This site doesn't offer support for third party plugins – Pieter Goosen Commented Jul 21, 2014 at 18:53
  • I believe this has nothing to do with the plugin. Just mentioned it as context. This is more a question on why meta_value_num is not working in this instance for orderby. Or more specifically why sorting meta_value as integer doesn't work, or how do I do it in a wp_query. Thanks for the formatting btw, will keep in mind next time. – Man_Pat Commented Jul 21, 2014 at 18:57
  • 1 Then please be specific in your question. File an edit and add all relevant info to your question. Also add what you have done so far to solve your problem and where you are failing. As it stand, your question is off topic as you are asking support for a third party plugin. – Pieter Goosen Commented Jul 21, 2014 at 19:00
  • 1 var_dump $scoreboard and see what the query looks like and if it's being cast as int. – Milo Commented Jul 21, 2014 at 19:04
Add a comment  | 

1 Answer 1

Reset to default 0

It's not the plugin that is causing the issue it is the fact you are not querying the database correctly. It is not looking for integers your value is currently being stored as a string. To fix this you need to somehow change the value to a integer before it is passed to your array.

发布评论

评论列表(0)

  1. 暂无评论