WordPress:获取 ACF Post Object 选择(Post ID)并将其与 $post = get_post() 一起使用;

WordPress: Get ACF Post Object selection (Post ID) and use it with $post = get_post();

我很难理解如何同时使用两个 PHP 片段。

我的情况:标准 WordPress Post 类型“Pages”有自己的 ACF 字段“header-selection”。该字段是 Post Object 并且 return 格式是 Post ID。可以从 CPT "Headers".

的可用帖子中进行选择

使用下面的代码,我可以得到选择的 Post/ID:

$value = get_field( "header-selection" );

现在我想在下面的代码中集成ID:

$post = get_post(18);
$the_content = apply_filters('the_content', $post->post_content);
if ( !empty($the_content) ) {
  echo $the_content;
}

我希望选择 ACF 字段“header-selection”而不是 Post ID“18”。

如果我弄错了,我很抱歉。不幸的是,我在理解 PHP 时遇到了问题。 我将非常感谢建议的解决方案或想法。

将 ACF 值保存到一个变量,而不是使用该变量代替硬编码 ID,如下所示:

$header_selection_id = get_field( "header-selection" );
$post = get_post($header_selection_id);