for*_*kie 0 sorting wordpress meta-key
我正在尝试使用WP_Query和meta_query参数查询帖子:
$args = array(
'post_type' => 'produkty',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'produkt_aktywny',
'value' => '1',
'compare' => '='),
array(
'key' => 'produkt_dostepnosc',
'value' => '1',
'compare' => '=')
)
);
$query = new WP_Query( $args );
Run Code Online (Sandbox Code Playgroud)
我应该添加什么来通过另外两个键('produkt_kategoria'和'produkt_cena')来订购结果?WP Codex中没有任何关于它的内容,但是:
"Do you know how to sort the query if the meta_value is an array? Write it here :)"
Run Code Online (Sandbox Code Playgroud)
据此,我相信按多个元值排序是可能的.
小智 12
我想显示自定义帖子类型的帖子.通过自定义字段对其进行排序,并添加一个参数,其他自定义字段是特定值,以仅显示选择的帖子.
例如.选择custom_posts,其中custom_field_a = xxxx并按custom_field_b排序
我花了一段时间才弄清楚,在搜索时,我一直在这个帖子上磕磕绊绊.因此,对于具有相同问题的所有人来说,这是最终完成它的(简化)代码.
$args = array(
'post_type' => 'my_custom_post_type',
'meta_key' => 'custom_field_b',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'custom_field_a',
'value' => get_post_meta(get_the_ID(),'other_field',true),
'compare' => '='
)
),
);
$loop2 = new WP_Query($args);
Run Code Online (Sandbox Code Playgroud)
你看,这是一个循环循环,因此价值是动态的.当然,这也可能是硬编码的.
希望它可以帮到某人!
| 归档时间: |
|
| 查看次数: |
17434 次 |
| 最近记录: |