$loop3 = new WP_Query( array(
\'posts_per_page\' => 10000,
\'post_type\' => \'volunteers\',
\'meta_key\' => \'state\',
\'meta_value\' => $stateselect,
\'meta_compare\' => \'=\',
\'meta_key\' => \'volunteer_type\',
\'meta_value\' => \'painter\',
\'meta_compare\' => \'=\',
) );
您好。我是PHP和WordPress的新手。我很难理解WP\\U查询是如何工作的。我正在尝试获取一个类似以下伪代码的数据集:
state=$stateselect AND志愿者\\u type=画家
上面的代码似乎正在重写“meta\\u key”并返回所有“states”的结果,因为“志愿者类型”似乎正在被覆盖。我如何。。。
检索两个不同标准的结果,这两个不同的meta\\u-key标准是否等效此外,我想按参数中不包含的meta\\u键对结果进行排序。e、 g.有一个叫做“节”的字段,它是逐峰的。如何对不属于参数的字段进行排序ASC或DESC?
谢谢
SO网友:Tony Djukic
您想使用较新的meta_query
方法论
您建立了meta_query
然后对需要满足的不同条件使用数组,并在它们前面加上关系relation => \'AND\'
或relation => \'OR\'
$loop3 = new WP_Query( array(
\'posts_per_page\' => 10000,
\'post_type\' => \'volunteers\',
\'meta_query\' => array(
\'relation\' = \'AND\',
array(
\'key\' => \'state\',
\'value\' => $stateselect,
\'compare\' => \'=\',
),
array(
\'key\' => \'volunteer_type\',
\'value\' => \'painter\',
\'compare\' => \'=\',
),
),
) );
Codex在这里有一篇文章:
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parametersNote真是太多了posts_per_page
.
SO网友:amiad
You should use meta_query:
$loop3 = new WP_Query( array(
\'posts_per_page\' => 10000,
\'post_type\' => \'volunteers\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'state\',
\'value\' => $stateselect,
),
array(
\'key\' => \'volunteer_type\',
\'value\' => \'painter\',
),
));