Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
Created March 6, 2013 22:18
Show Gist options
  • Save LinzardMac/5103629 to your computer and use it in GitHub Desktop.
Save LinzardMac/5103629 to your computer and use it in GitHub Desktop.
Adding a link that gets the recent post from a CPT and putting it in a specified menu
// Filter wp_nav_menu() to add link to recent lottery
function new_nav_menu_items($items) {
// Get the most recent post
$the_query = new WP_Query( 'post_type=toy_lotteries' , 'posts_per_page=1' );
// Pull the link
while ( $the_query->have_posts() ) : $the_query->the_post();
$latest_link = '<li> <a href="' . get_permalink() . '">Lotteries</a></li>';
endwhile;
$items = $latest_link . $items;
return $items;
}
add_filter( 'wp_nav_menu_menu-left_items', 'new_nav_menu_items' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment