Elementor Posts Query: More Posts by the Same Author
Adds a custom query ID "wpide_same_author" that lists other posts by the author of the post being viewed, for "More from this writer" sections.
Opens WPIDE on
Code
add_action( 'elementor/query/wpide_same_author', function ( $query ) {
if ( ! is_singular() ) {
return;
}
$post = get_queried_object();
if ( ! $post instanceof WP_Post ) {
return;
}
$query->set( 'author', (int) $post->post_author );
$query->set( 'post__not_in', array( $post->ID ) );
$query->set( 'ignore_sticky_posts', true );
} );
Notes
Type wpide_same_author in the Query ID field of a widget in your single post template.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.