Custom arguments in author page loop / query
-
I have a post meta field in which a secondary author is registered (key=sec_author_name). On the author page (website/author/name) I’d like to show posts from this author or post where this author is the secondary author.
To do this efficient I use the pre_get_posts action.
First I use unset to remove the current filter on author_name: unset( $query->query_vars[‘author_name’] );And then I’d thought to do something with meta_query, but I can’t figure it out.
I currently have this:
if ( $query->is_author() && $query->is_main_query()) { unset( $query->query_vars['author_name'] ); $query->set( 'meta_query', array( 'relation' => 'OR', array( 'key' => 'sec_author_name', 'value' => 'jorim', 'compare' => '=' ), array( 'key' => 'author_name', 'value' => 'jorim', 'compare' => '=' ), ) ); }
And this gives me a 404 ??
It’s probably because I try to compare a meta field with a non meta field with meta_query… Is this possible this way?
If not, I don’t mind adding a custom piece of query to the query to retrieve the right post ID’s..
Thank in advance!
Jorim
- The topic ‘Custom arguments in author page loop / query’ is closed to new replies.