This function looks for the most recent post and adds it to any menu item with #placeholder as a link.
/**
* Look for placeholder url and replace it with latest post
*
* @param $items
*
* @return mixed
*/
function latest_conference_item( $items ) {
// Get the latest conference
$latestpost = get_posts( array(
'numberposts' => 1,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
'post_type' => 'post'
) );
foreach ( $items as $item ) {
if ( empty( $latestpost ) || '#placeholder' != $item->url ) {
continue;
}
// Replace the placeholder with the real URL
$item->url = get_permalink( $latestpost[0]->ID ) . 'program';
}
return $items;
}
if ( ! is_admin() ) {
add_filter( 'wp_get_nav_menu_items', 'latest_conference_item', 10 );
}