Last active
August 21, 2021 11:13
-
-
Save janmyszkier/45f1ccb9392cb45712053825a99c4492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//for: Molongui authorship version 4.3.9 | |
//bug: does not render correct author | |
/** | |
* To reproduce: | |
* 1. open author.php | |
* 2. paste the php code into it | |
* 3. open ANY author page, let's call it John doe, with slug of blog.com/authors/john-doe | |
* 4. notice how you will get 10 posts, but all of them will say it's author is john doe instead of the real author | |
*/ | |
//Expected result: Each post has correctly shown an author that's that's visible in the WP Admin -> Posts in the author column | |
//Actual result: when entering from an author page, the current author will always override the author in the loop | |
$args = array( | |
'posts_per_page' => 10, | |
'ignore_sticky_posts' => true, | |
'meta_key' => 'post_views_count', | |
'orderby' => 'meta_value_num', | |
'order' => 'DESC', | |
); | |
$popular_posts_query = new WP_Query($args); | |
if ( $popular_posts_query->have_posts() ) : ?> | |
<?php while ( $popular_posts_query->have_posts() ) : ?> | |
<?php $popular_posts_query->the_post(); | |
$post = get_post(); | |
$authorId = (int) get_post_field('post_author', $post->ID); | |
?> | |
<a href="<?php echo get_the_permalink(); ?>" target="_self"><?php echo shorten_text_by_words(the_title('', '', false), 9); ?></a> | |
<div> | |
<img alt="" src="<?php echo get_avatar_url($authorId, ['size' => '96']); ?>" class="avatar avatar-96 photo" height="96" width="96"> | |
<a href="/author/<?php the_author_meta('user_nicename',$authorId); ?>"><?php echo get_the_author_meta('user_firstname',$authorId); ?> <?php echo get_the_author_meta('user_lastname',$authorId); ?></a> | |
</div> | |
<?php endwhile; ?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment