0

I'm working on a site that allows multiple authors on posts by using an "additional authors" Posts to Posts connection type. Posts still have a standard author, but they can optionally have additional authors.

I'd like to modify the author archive query to include all posts by the author, including those where they are an "additional" author. This isn't as simple as just adding parameters to the main author query, so in pre_get_posts I'm combining two queries by getting the matching post IDs from both, then running a post__in query.

Thats works, but I can't figure out how to pass the results of that query to the author template. Changing the author query var means that the site doesn't show the author archive template.

tl;dr - can you use pre_get_posts to fully customize the author archive query, and include posts that are not actually authored by that user?

1 Answer 1

0

The only way that I've found to override the main author archive query in a way that will include posts that aren't created by the specified user is by using the posts_where filter.

For example:

        $post_ids = function_that_gets_desired_post_ids();

        add_filter('posts_where', function($where) use ($post_ids){

            $post_ids = array_map(function($id){
                return (int) $id;
            }, $post_ids);

            $in = implode(',', $post_ids);
            $where .= " OR (ID IN ($in) AND post_type = 'post')";
            return $where;

        });

Using something like this doesn't make me feel good, but it does work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.