Php Wordpress ACF将变量作为值传递到args数组

Php Wordpress ACF将变量作为值传递到args数组,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我正在尝试创建一个动态的帖子布局。在后端,我有一个字段,在其中输入要传入的帖子集合的slug $subfield值为recipe。出于某种原因,当我编写'post_type'=>$subfield时,它不起作用。它只有在我硬编码时才能工作。当我将$subfield变量作为值传递给“post_type”时,是否有任何关于该变量为何为空的见解 <?php if ( get_row_layout() == 'list_posts' ) { // $subfield = the_sub

我正在尝试创建一个动态的帖子布局。在后端,我有一个字段,在其中输入要传入的帖子集合的slug

$subfield值为recipe。出于某种原因,当我编写'post_type'=>$subfield时,它不起作用。它只有在我硬编码时才能工作。当我将$subfield变量作为值传递给“post_type”时,是否有任何关于该变量为何为空的见解

<?php 



if ( 
get_row_layout() == 'list_posts' ) {

// $subfield = the_sub_field( 'custom_post_type' );
// this variable has a string value of recipe in the backend

    
$args = array(
  'post_type'   => 'recipe' //works when hardcoded, not when $subfield is passed
 );


 $the_query = new WP_Query($args );

 if (
 $the_query->have_posts() )
 :while (
 $the_query->have_posts() )
 : $the_query->the_post();
 ?>

  <a href="<?php echo the_permalink();?>">
     <?php echo the_title();?>
  </a>

  

  <?php wp_reset_postdata();
      endwhile;
      endif;
    } 

  ?>

根据:
子字段()显示中继器或灵活内容字段循环中特定子字段值的值。此函数基本上与echo get_sub_field()相同。
。因此,它不会将预期值返回到
$子字段
变量。让我们使用
get\u sub\u字段()

$subfield=get_sub_字段('custom_post_type');
WordPress世界中有一个隐含的约定:显示值的函数的名称将以
the
开头,返回值的函数的名称将以
get
开头