I'm trying to work out or even find a way to list all the posts according to a custom field of the authors. I'm using WP User Frontend Pro and the plugin allows me to create custom fields for the user/author registration page.

e.g. All the schools need to register and choose which years they teach. So I want to list all the posts by those schools that teach specific years.

If I was talking about WP_Query for custom fields assigned to posts then that'd be easy as below, but how do I do this for an author's custom field?

// WP_Query arguments
$args = array (
    'post_type'              => array( 'post' ),
    'meta_query'             => array(
            'key'       => 'school_year',
            'compare'   => '=',
            'type'      => 'CHAR',

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        // do something
} else {
    // no posts found

// Restore original Post Data
  • WP_User_Query works much like WP_Query. It's not clear what you're trying to query for though- posts by users who have a specific value in user meta? – Milo Apr 22 '16 at 17:08
  • Not clear? I'm trying list all the posts, with authors that have a specific value in user meta. I don't want to list the authors, I want to list the posts that's why I thought WP_Query would be best. – Pete Apr 22 '16 at 17:13
  • WP_Query can't do that. You need to query for authors, then query for each author's posts. – Milo Apr 22 '16 at 17:24
  • @Milo have you seen any sort of example that had those two elements put together? – Pete Apr 23 '16 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.