Ask your WordPress questions! Pay money and get answers fast! (more info)

Redirect to latest post of an author WordPress



I use Quick Page/Post Redirect Plugin. I need a solution to redirect a post of an author to his latest post (should load the full content of the latest post of the author)


Answers (3)


Liam Bailey answers:

Can you clarify... You want a solution so that when a person clicks on a certain post they are redirected to the author of that post's latest post. Is this for a View latest post by this author sort of thing? If so why not just make the link to the author's latest post like so:

global $post,$wpdb;
$latest_post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM wp_posts WHERE post_author = %d AND post_status='publish' ORDER by post_date DESC LIMIT 1",$post->post_author));
$link = get_permalink($latest_post);
//then simply use the link as the href.


You may have a template file in your theme called category-author.php, a file specifically to display your author category, or maybe you have conditional logic in another theme file. Wherever the while loop is that is outputting your author list insert the following right below the line while(have_posts()) : the_post() :

global $wpdb;

$latest_post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM wp_posts WHERE post_author = %d AND post_status='publish' ORDER by post_date DESC LIMIT 1",$post->post_author));

$link = get_permalink($latest_post);

//then simply use the link as the href for your thumbnail links


Ok, this gives us a problem as your authors in category authors are posts, but you need to pull out posts by author which is a user_id, you need to have some correlation between the two. Assuming your slug for the author's bio post matches up to their user_nicename field on the author you could do.

You need to add this to your functions.php file:


function go_to_latest($link) {

if (in_category('authors')) { //where author is slug of author category

global $post;

if ($the_post = get_posts('author_name='.$post->post_name.'&posts_per_page=1')) {

$link = get_permalink($the_post[0]->ID);



return $link;

So, when the amazing_posts_widget plugin tries to use the_permalink on posts that are in the authors category our function kicks in and replaces the link. The only problem will be the correlation between author (user) nicename and bio post slug, if you dont have too many authors you could create this link without too much trouble.

Senerh comments:

Hi Liam,
Can you explain where exactly to put the codes? In php file?


Liam Bailey comments:

Hi Sener,

You want to replace the link on the author thumbnail's with the link generated in my code. Wordpress doesn't offer an author bio page by default so I dont know what you mean by your thumbnail's currently link to the author's bio post. By default Wordpress author pages list latest posts, and even the list authors functions dont have a thumbnail, so I am thinking you must have some custom code for this. If you could let us have a look at that, or even better send ftp details to me at info[at] and I will apply the change for you. If I can find out what functions you are using to display your author's there will probably be a filter I can use to input the link to the latest post in place of the existing link.

Senerh comments:

Thank you Liam,
Actionally an hyperlink to the most recent post of the specified author would also work. I am sorry for the confusion, it's diffucult somtimes to give the message because I have no expert experiance of wordpress :)

So for example, is there some code I can use as follow.

I have 5 authors. A, B, C, D, E
Link "Goto Author A Last Post"
When you click on this link, you open the most recent content of author A.

Is this is possible, I can use the same link code for my thumnails.

I am still trying to figure out where I can put your code. Sorry for my lack of understanding :(

Liam Bailey comments:

Arnav has given you a solution that will show the user's latest post at /author/author_name but I don't think this is what you are looking for.

You say you have a page that lists your authors with a thumbnail link to their bio post. This isn't a Wordpress template file as standard, so what is generating this page. Is it a page template within the theme, or is it a shortcode? If it is a page template please post the content of the page-template file, if it is shortcode please tell me which plugin you are using or if not a plugin tell me which theme you are using so I can do some digging. Once I know where the author list is coming from I can help you properly.

Liam Bailey comments:

I just read your message to Arnav. Please post the contents of category.php from your theme, if you dont have category.php please post archive.php and if you dont have that please post index.php

Liam Bailey comments:

Or you might have a template file specifically for the author category. If you do have a file in your theme something like category-author.php it probably has a while loop where we can insert my code:

while (have_posts()) : the_post();
global $wpdb;

$latest_post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM wp_posts WHERE post_author = %d AND post_status='publish' ORDER by post_date DESC LIMIT 1",$post->post_author));

$link = get_permalink($latest_post);

//then simply use the link as the href for your thumbnail links

If you dont have a category-author.php file, take category.php and save it as category-author.php where author is the slug of your author category, or you can use the id if you wish. Then add the code above into the while loop, save and ftp to your theme directory. You should be good to go.

Senerh comments:

I have Category.php

<?php get_header(); ?>

<?php if( is_home() && ! is_paged() ) : ?>
<?php if( pinboard_get_option( 'slider' ) ) : ?>
<?php get_template_part( 'slider' ); ?>
<?php endif; ?>
<?php get_sidebar( 'wide' ); ?>
<?php get_sidebar( 'boxes' ); ?>
<?php elseif( ( is_home() && is_paged() ) || ( ! is_home() && pinboard_get_option( 'location' ) ) ) : ?>
<?php pinboard_current_location(); ?>
<?php endif; ?>
<div id="container">
<section id="content" <?php pinboard_content_class(); ?>>

<?php if( is_category( pinboard_get_option( 'portfolio_cat' ) ) || ( is_category() && cat_is_ancestor_of( pinboard_get_option( 'portfolio_cat' ), get_queried_object() ) ) ) : ?>
<?php pinboard_category_filter( pinboard_get_option( 'portfolio_cat' ) ); ?>

<?php endif; ?>
<?php if( have_posts() ) : ?>
<div class="entries">
<?php while( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
</div><!-- .entries -->
<?php pinboard_posts_nav(); ?>
<?php else : ?>
<?php pinboard_404(); ?>
<?php endif; ?>
</section><!-- #content -->
<?php if( 'no-sidebars' != pinboard_get_option( 'layout' ) && 'full-width' != pinboard_get_option( 'layout' ) && ! is_category( pinboard_get_option( 'portfolio_cat' ) ) && ! ( is_category() && cat_is_ancestor_of( pinboard_get_option( 'portfolio_cat' ), get_queried_object() ) ) ) : ?>
<?php get_sidebar(); ?>
<?php endif; ?>
<div class="clear"></div>
</div><!-- #container -->

<?php if( is_active_sidebar( 6 ) ) : ?>
<div id="footer-area" class="widget-area" role="complementary">
<?php dynamic_sidebar(6); ?>
<div class="clear"></div>
</div><!-- #footer-area -->
<?php endif; ?>

<?php wp_footer(); ?>

Senerh comments:

I use Plugin "Amazing Post Widget" to show the thumbnails of the category Authors.

When I click on the thumbnail it go's a static post of the author (which explains authors biography, inserterd manually). It's a standard post actually.

So now, when we click to the thumbnail of a author, it has to go to the latest post of that author.