如何在代码中插入 php var

how to insert php var in code

我使用 wordpressadvanced custom fields:

得到了这个工作代码
$include = get_pages('include=1575');
$title = apply_filters('the_title',$include[0]->post_title);
$content = apply_filters('the_content',$include[0]->post_content);

我想创建一个 var 来替换 include=1575 中的 post_id。我得到这个变种使用:

$site_id = the_field('id_grundgedanke'); // output exp: 1575

我怎样才能把它们结合起来?我尝试了以下方法:

 $site_id = the_field('id_grundgedanke');
 $include = get_pages('include=' . $site_id);
 $title = apply_filters('the_title',$include[0]->post_title);
 $content = apply_filters('the_content',$include[0]->post_content);

哪个不起作用。

使用get_field() instead of the_field().

get_field() - Returns the value of the specified field.

the_field() - Displays the value of the specified field. This function is the same as echo get_field($field_name);

更正后的代码:

 $site_id = get_field('id_grundgedanke'); // use get_field
 $include = get_pages("include=" . $site_id);
 $title = apply_filters('the_title',$include[0]->post_title);
 $content = apply_filters('the_content',$include[0]->post_content);