如何在导航菜单中添加最新的ACF帖子?

时间:2019-03-27 12:06:04

标签: wordpress advanced-custom-fields

我正在尝试在主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;
}

0 个答案:

没有答案