So, here is the issue:
I am using a plugin named User Submitted Posts, and it works great on its part. However, I still want to have that user content page the Twenty Twenty Four theme has by default, which you can access when you click on the user's name. The issue is, USP doesn't require logins, so these posts are all actually submitted by the same user, whose display name is being overridden to show as the user_submit_name, a custom field in USP's posts.
This makes the author archive display all the posts, because technically they are all assigned the same author.
What I want is to modify the query on the archive page to sort through posts using this custom field, so that it still works. I am a complete beginner though, so this is proving rather difficult.
The main issue I'm facing is that I know how to modify the author archive query, but I don't know how to pass the user_submit_name it should use to the function. Basically, I have no way of telling the archive for which name it should be sorting, aside from hard coding it.
Here is my code so far:
function wpd_author_query( $query ) {
if ( $query->is_author()
&& $query->is_main_query() ) {
// your code to set $current_user_name here
$query->set( 'meta_key', 'user_submit_name' . /*author name*/);
$query->set( 'posts_per_page', 4);
// EDIT
// unset the requested author
unset( $query->query_vars['author_name'] );
}
}
add_action( 'pre_get_posts', 'wpd_author_query' );
To recap, I need to somehow pass the custom field "user_submit_name" from a post to the function that modifies the author query, when the viewer clicks on the author link.
Does anyone know how I could go about this? Also if you have any better ideas how to do this, which you probably do, feel free to share them. Thank you.