Created
March 6, 2013 22:18
-
-
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
This file contains hidden or 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
// 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