Hi Michael,
So I decided to try the coding route. But using a plugin. I’m not sure if I’m doing things right here… (Actually, I’m sure I’m not doing it right.)
– I want CPT post to appear in an author archive.
– My custom post type is called (in Swedish) “recensioner” (which translates into “reviews”)
– I installed a plugin called “Code Snippets” that allows me to add, well, code snippets, without editing the theme files.
Based on the two previous support questions (linked above) I have added the following code snippet using the “Code Snippet” plugin:
function wpse107459_add_cpt_author( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( $query->is_author() ) {
$query->set( 'post_type', array( 'recensioner' ) );
}
}
add_action( 'pre_get_posts', 'wpse107459_add_cpt_author' );
It does not work as expected.
In your previous reply you asked “Are you sure you’re visiting the right URL?”. Well, no, I am not. The author archive URL that I look at looks like this:
[URL]/author/britt/
[URL] – it is not (yet) a public site so I don’t include the URL here.
“britt” is the name of one of the authors.
This is what happens:
If the code snippet is not active: The archive shows only the standard posts, not the CPT (as expected).
If the code snippet is active: The archive is empty. “It seems we can’t find what you’re looking for.” I was hoping that the CPT posts would now display but they don’t (and the standard ones have disappeared).
Ideally, I would be able to display both the standard posts and the CPT posts in an author archive. Preferably in the same archive, or alternatively in one archive for standard posts and another for CPT. Either of the two is acceptable.
What am I doing wrong?