WP_Query-按元值
1 个回答
- 投票数
-
- 2011-10-04
orderby
应该是meta_value_num
,或者是meta_value
,而不是键的名称.参见 WP_Query orderby参数.orderby
should bemeta_value_num
, ormeta_value
, not the name of the key. See WP_Query orderby parameters.-
工作了请客,为队友们喝彩.Worked a treat, cheers mate.
- 0
- 2011-10-04
- Adam Moss
-
谢谢!你是我的节约者!关于"meta_value_num",在WPCodex上没有提到任何地方.Thanks! You're my timesaver! Nowhere on WPCodex isn't mentioned about 'meta_value_num'.
- 0
- 2012-06-21
- BasTaller
-
小提示,如果该帖子尚不存在"meta_key",则该帖子将被忽略.Small note, if the `meta_key` does not exist for the post yet, the post will be ignored.
- 7
- 2015-12-02
- adamj
-
"meta_value_num"是可以分配给帖子类型的自定义帖子元吗?我需要能够为每个帖子编辑此值.is `meta_value_num` a custom post meta that you can assign to post types? I need to be able to edit this value per post.
- 0
- 2017-04-25
- RobBenz
-
@RobBenz请参阅[自定义字段](https://codex.wordpress.org/Custom_Fields)以了解帖子元.@RobBenz See [Custom Fields](https://codex.wordpress.org/Custom_Fields) to learn about post meta.
- 0
- 2017-04-25
- Milo
-
谢谢,我熟悉自定义帖子元.我想在WC产品中添加一个名为`search_order`之类的元框.这样,当显示搜索结果时:我可以控制其显示顺序.我应该调用要添加"meta_value_num"的自定义帖子元吗?thank you, I am familiar with custom post meta. I want to add a meta box to WC products, called `search_order` or something. so that when the search results are displayed: I can have the ability to control the order of their display. should I call the custom post meta that I am adding `meta_value_num`
- 0
- 2017-04-25
- RobBenz
-
或者`meta_value_num`只是采用基于帖子的'meta_key'=>'search_order'的值or does `meta_value_num` just take the value of whatever 'meta_key' => 'search_order' is based on the post
- 0
- 2017-04-25
- RobBenz
-
@RobBenz`meta_value_num`告诉WP通过数字元值对结果进行排序.这不是键名.@RobBenz `meta_value_num` is telling WP to order the results by a numeric meta value. It's not the key name.
- 0
- 2017-04-25
- Milo
-
如何更改"meta_value_num",以便特定帖子在搜索结果中"排名"更高how do i change `meta_value_num` so that a particular post will "rank" higher up the search results
- 0
- 2017-04-25
- RobBenz
-
@RobBenz您可能应该就此主题开始一个新问题.第1步给元键分配任意值,我们称其为"my_meta_key",以便每个帖子生成所需的顺序.步骤2您在查询中将"meta_key"设置为"my_meta_key".这告诉WordPress查询具有该密钥的帖子.步骤3在查询中将`orderby`设置为`meta_value_num`.这告诉WordPress不仅要查询具有"my_meta_key"的帖子,还要按该关键字进行数字排序.该查询参数是您将看到或使用"meta_value_num"的唯一位置.@RobBenz You should probably start a new question on this topic. Step 1 Assign whatever value you want to your meta key, let's call it `my_meta_key`, for each post to generate whatever order you want. Step 2 You set `meta_key` in your query to `my_meta_key`. This tells WordPress to query for posts that have that key. Step 3 Set `orderby` in your query to `meta_value_num`. This tells WordPress to not only query posts with `my_meta_key`, but to also order numerically by that key. That query argument is the only place you will ever see or use `meta_value_num`.
- 1
- 2017-04-25
- Milo
-
@adamj有什么解决方法吗?我需要对所有帖子进行排序,无论该帖子是否存在meta_key.@adamj is it any workaround this? I need sort all posts, regardless that meta_key exist for the post or not.
- 2
- 2018-02-22
- unbreak
-
@unbreak一种简单的解决方案是在运行订单查询之前解析所有帖子并向其中添加`meta_key`@unbreak the simple solution is to parse over all the posts and add the `meta_key` to them prior to running the order query
- 1
- 2018-02-23
- adamj
我已经检查了一下,还没有找到一个可行的答案.我有一个带有以下参数的WP_Query:
我想通过自定义帖子字段
client_feedback_score
(从最低到最高)对结果进行排序.但这似乎不起作用...任何人都可以向我指出正确的方向吗?编辑(已解决):
感谢Milo的回应,以下是通过数字元值进行排序的工作代码: