简体   繁体   English

WP_Query-按其他帖子类型的元类型排序帖子

[英]WP_Query - Ordering posts by meta type of another post type

I have a custom post type called BID which contains a user's bids (similar to freelancer.com, upwork, etc) However I need the BID results on the page to be ordered by meta stored in a users profile, which is a custom post type PROFILE. 我有一个名为BID的自定义帖子类型,其中包含用户的出价(类似于freelancer.com,upwork等),但是我需要页面上的BID结果由存储在用户个人资料中的元数据进行排序,这是一个自定义帖子类型轮廓。

How would I go about doing this? 我将如何去做呢?

Here is my current Query 这是我当前的查询

WP_Query( array(  'post_type' => array(BID, PROFILE),
                                'post_parent' => get_the_ID(),
                                'orderby'   => 'meta_value_num',
                                'order'     => 'DESC',
                                'meta_key'  => 'rating_score',
                                'post_status' => array('publish','complete', 'accept', 'unaccept')
                            )
                        );

I don't know of a way to do this with WP_Query alone so I'd probably write some extra PHP to do this. 我不知道一种单独使用WP_Query做到这一点的方法,因此我可能会写一些额外的PHP来做到这一点。 I'm not sure exactly how things are set up so I can't write code, but here's the general idea. 我不确定具体的设置方式,因此我无法编写代码,但这是一般的想法。

  1. Generate your bid results without paying much attention to how they are ordered. 生成出价结果时,无需过多关注订购方式。

  2. Loop through your generated query result and, for each item, define a new attribute that fetches the meta information from the corresponding profile meta. 遍历生成的查询结果,并为每个项目定义一个新属性,该属性从相应的配置文件元中获取元信息。

  3. Order your array using this new meta information. 使用此新的元信息订购阵列。 You might be able to use PHP's sort() function, or if you need a more general function, try usort() 您也许可以使用PHP的sort()函数,或者如果需要更通用的函数,请尝试usort()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM