从用户名或用户 ID 向主题添加多个 Instagram 提要

Add multiple Instagram feeds to theme from username or user ID

我需要能够让用户在自定义字段中输入他们的 Instagram 用户名或用户 ID。我需要提要来仅导出最近的图像,并且我找到了一个在大多数情况下都运行良好的插件。我正在使用 Smash Balloon 提供的 Instagram Feed,我发现我可以在我的主题中使用以下代码以我需要的方式显示提要:

<?php echo do_shortcode("[instagram-feed id='username']"); ?>

我需要能够将 username 替换为用户可以插入到我创建的高级自定义字段文本字段中的用户 ID。我知道我可以用这个回应代码:

<?php the_field('instagram_field'); ?>

如何获取从我的 the_field 参数回显的内容并将其插入到我的短代码中的 username space?

如果有更好的方法允许将多个提要添加到自定义 Post 类型中,我愿意接受,但这解决了我在样式设置、需要多个提要等方面遇到的所有其他问题。

您可以为高级自定义字段分配一个变量,以便它在 Instagram 简码用户名属性中得到回应。

$custom_acf_field = the_field('instagram_field');


echo do_shortcode("[instagram-feed id=$custom_acf_field]");

然后允许多个 feeds/Shortcodes 你可以将上面的内容包装在一个 foreach 循环中,其中包含一些与每个用户相关的参数。

答案接近正确。

问题在于声明字段,提供的答案使用 the_field 而不是 get_field。应该用于存储变量。

$custom_acf_field = get_field('instagram_field');
echo do_shortcode("[instagram-feed id='$custom_acf_field']");

这应该可以解决,如果不行,您可能希望单独声明简码:

$custom_acf_field = get_field('instagram_field');
$insta_code = [instagram-feed id='$custom_acf_field'];
echo do_shortcode($insta_code);