Leave a Reply

2 comments

  1. For anyone who may have a similar need, I solved this the following way (on authors.php):

    First I get the author ID:

    $author = get_user_by( 'slug', get_query_var( 'author_name' ) );
    
    // ID is accessed this way:
    $author_id = $author->ID;
    

    I then created a custom query:

            $query = "
                    SELECT p.* 
                    FROM   $wpdb->postmeta m 
                                 JOIN $wpdb->posts p 
                                     ON p.id = m.post_id 
                    WHERE  ( m.meta_key = 'medium_post_photographers' 
                                     AND m.meta_value = '$author->ID' ) 
                                    OR ( m.meta_key = 'medium_post_videographers' 
                                             AND m.meta_value = '$author->ID' ) 
                                         AND p.post_status = 'publish' 
                    UNION DISTINCT 
                    SELECT * 
                    FROM   $wpdb->posts p 
                    WHERE  post_author = $author->ID 
                                 AND p.post_status = 'publish' 
                    GROUP  BY p.id 
                    ORDER  BY post_date DESC 
            ";
    

    And finally use the following to get the results:

     $author_posts = $wpdb->get_results($query, OBJECT);   
    

    Here is a simplified version of my loop to display the results:

    <?php if ( $author_posts ) : ?>
        <?php global $post; ?>
        <?php foreach ( $author_posts as $post ) : setup_postdata($post); ?>
            <h6><?php echo the_title(); ?></h6>
            ...
        <?php endforeach; ?>
    <?php else: ?>
        <div class="alert">There are no posts in this category.</div>
    <?php endif; ?>
    

    I hope this helps someone!