我在我的网站上使用了utimate会员插件。对于每个成员(作者),我都有一个字段来存储成员性别。(Homme / Femme)
数据存储在我的数据库中,在wp_usermeta中。
元关键字是“性别”,元值是"Homme“或"Femme”。

我正在尝试编写一个wp-query来显示所有作者的所有帖子,但只显示"Homme“作者,而另一个查询仅显示"Femme”。
下面是我的wp-query,用来显示所有帖子,而不是按性别过滤:
<?php $custom_query_args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'DESC',
'orderby' => 'date',
);
$custom_query = new WP_Query( $custom_query_args ); ?>工作正常。
这是我到目前为止试图从"Homme“性别获得的帖子,但它不起作用……我想我需要在某个地方添加对帖子作者ID的引用,但我找不到解决方案。
<?php $custom_query_args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'gender',
'value' => 'Homme',
'compare' => '='
),
),
'order' => 'DESC',
'orderby' => 'date',
);
$custom_query = new WP_Query( $custom_query_args ); ?>我不知道是否有一种方法可以用插件本身做到这一点,但我非常确定它可以通过一个简单的wp-query来完成。
有人能帮我吗?
谢谢。
发布于 2016-04-22 00:21:49
更改此设置:
<?php $custom_query_args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'gender',
'value' => 'Homme',
'compare' => '='
),
),
'order' => 'DESC',
'orderby' => 'date',
);
为此:
<?php $custom_query_args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_key' => 'gender',
'meta_value' => 'Homme',
'order' => 'DESC',
'orderby' => 'date',
);
https://stackoverflow.com/questions/36774527
复制相似问题