Oh, the comment on your question makes it clear. In case you would like to always return a fresh latest post, no matter the page with menu link gets or not refreshed must be solved in another way.
At first: Create new page, let’s say: “Latest post” – note it’s ID.
And than add this into your functions.php:
function binda_redirect_to_latest( $query ) {
$page_id = 234; //ID of your page with Latest post
if ( $query->is_page( $page_id ) && $query->is_main_query() ) {
$args = array( 'numberposts' => 1, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'magazine_issue', 'post_status' => 'publish' );
$latest_post = get_posts( $args );
foreach( $latest_post as $p ){
$query->set( 'p', $p->ID );
$query->set( 'page_id', '' );
}
}
return $query;
}
add_action( 'pre_get_posts', 'binda_redirect_to_rand' );
Voilá
If you do not want to create an extra page, you can register a new query variable and chceck for it’s present in pre_get_posts hook. This way:
add_filter( 'query_vars', 'my_query_vars' );
function my_query_vars( $vars ) {
$vars[] = 'latest_post';
return $vars;
}
Modified pre_get_posts hook callback:
function binda_redirect_to_latest( $query ) {
if ( $query->is_home() && isset($query->query_vars['latest_post']) && $query->query_vars['latest_post'] == 1 && $query->is_main_query() ) {
$args = array( 'numberposts' => 1, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'magazine_issue', 'post_status' => 'publish' );
$latest_post = get_posts( $args );
foreach( $latest_post as $p ){
$query->set( 'p', $p->ID );
}
}
return $query;
}
add_action( 'pre_get_posts', 'binda_redirect_to_rand' );
To create a ling, you add_query_arg:
echo add_query_arg( 'latest_post', 1, get_bloginfo('url') );