我正在尝试在主navBar
中添加最新文章的链接。结果需要限制为ACF
个帖子类型。我不确定如何引用ACF
帖子类型。我相信我没有正确使用类别术语。
//用最新文章的URL替换自定义URL占位符
function replace_placeholder_nav_menu_item_with_latest_post( $items, $menu, $args ) {
// Loop through the menu items looking for placeholder(s)
foreach ( $items as $item ) {
// Is this the placeholder we're looking for?
if ( '#latestpost' != $item->url )
continue;
// Get the latest post
$latestpost = get_posts( array(
'numberposts' => 1,
'category' => 'shows',
) );
if ( empty( $latestpost ) )
continue;
// Replace the placeholder with the real URL
$item->url = get_permalink( $latestpost[0]->ID );
}
// Return the modified (or maybe unmodified) menu items array
return $items;
}