0

I'm using utimate member plugin on my website. for each member (author), I have a field to store the member gender. (Homme / Femme).

the data is stored in my database, inside wp_usermeta.

meta key is "gender" and meta value is either "Homme", or "Femme".

enter image description here

I'm trying to write a wp-query to display all posts from all the authors, but only "Homme" authors, and another with only "Femme".

here is my wp-query to display all the posts without filtering by gender :

<?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 ); ?>

works fine.

Here is what I've tried so far to get only the posts from "Homme" gender, but it's not working... I think I need to add a reference to post author ID somewhere but I can't find the solution.

<?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 ); ?>

I don't know if there's a way of doin it with the plugin itself, but i'm pretty sure it can be done with a simple wp-query.

Can anybody help me with this ?

thanks.

mmdwc
  • 1,095
  • 6
  • 27
  • 53

1 Answers1

0

Change this:

<?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',
);

For this:

<?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',
);
neoprez
  • 349
  • 2
  • 11