Here’s how I understand this task: get posts (you can shape this any way you want by adding extra parameters to the query), for each post get its meta-box value (replace the key with yours), if value found add it to the menu’s HTML.
Note: code is not tested, it is more of an outline.
$html="";
$domain = 'your-domain'; // http://codex.wordpress.org/Function_Reference/_e
$meta_key = 'your-meta-key'; // TODO replace value with yours
$post_menu_items = get_posts( array(
'post_type' => 'post',
'post_status' => array( 'publish' ),
'numberposts' => -1
) );
if($post_menu_items){
$html .= '<ul>';
foreach ($post_menu_items as $key => $menu_item) {
$meta_title = get_post_meta($menu_item->ID, $meta_key, true);
if(!empty($current_meta)){
$html .='<li><a href="#' . $meta_title . '">' . $menu_item->post_title . '</a></li>';
}
}
$html="</ul>";
} else {
_e('No posts found.', $domain);
}
echo $html;
Thinking about it, you could even avoid the get_post_meta
call by supplying a meta_key
parameter into your get_posts
. You’re welcome to experiment with that.