Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用查询中的自定义字段/元键查询自定义帖子类型_Php_Wordpress_Types_Custom Post Type - Fatal编程技术网

Php 使用查询中的自定义字段/元键查询自定义帖子类型

Php 使用查询中的自定义字段/元键查询自定义帖子类型,php,wordpress,types,custom-post-type,Php,Wordpress,Types,Custom Post Type,我使用工具集类型设置了多个Wordpress自定义帖子类型,名称如下: no-9 八号 no-7 等等 我想做一个Wordpress查询,在另一个页面上显示来自这些自定义帖子类型之一的帖子。我想显示文章的页面还包含一个名为“issue no”的自定义字段,该字段与我想显示的自定义文章类型的名称相匹配 到目前为止,我的问题是: <?php query_posts(array( 'post_type' => 'n

我使用工具集类型设置了多个Wordpress自定义帖子类型,名称如下:

no-9

八号

no-7

等等

我想做一个Wordpress查询,在另一个页面上显示来自这些自定义帖子类型之一的帖子。我想显示文章的页面还包含一个名为“issue no”的自定义字段,该字段与我想显示的自定义文章类型的名称相匹配

到目前为止,我的问题是:

        <?php 
            query_posts(array( 
                'post_type' => 'no-9',
            ) );  
        ?>
        
        <?php while (have_posts()) : the_post(); ?>
                <h2><?php the_title(); ?</h2>
        <?php endwhile;?>

这可以显示来自帖子类型“no-9”的所有帖子,但是我希望调用是动态的,这样它可以根据匹配的自定义字段“issue no”进行更新

如何在查询中调用自定义字段名/元键?理论上类似于下面的内容,但是它没有将自定义字段放入查询中

        <?php 
            query_posts(array( 
                'post_type' => 'wpcf-issue-no',
            ) );  
        ?>
        
        <?php while (have_posts()) : the_post(); ?>
                <h2><?php the_title(); ?</h2>
        <?php endwhile;?>

最好使用$cpt这样的变量,并将自定义字段指定给它。不确定你在自定义字段中使用了什么插件,但我使用了ACF

$cpt = get_field('Your_post_type_name');
将$cpt放置在查询_帖子后,如下所示:

query_posts(array( 
    'post_type' => $cpt,
) );
    <?php 
    $cpt = get_field('your_selector');
        query_posts(array( 
            'post_type' => $cpt,
        ) );  
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
            <h2><?php the_title(); ?</h2>
    <?php endwhile;?>
它应该会起作用

所以它应该是这样的:

query_posts(array( 
    'post_type' => $cpt,
) );
    <?php 
    $cpt = get_field('your_selector');
        query_posts(array( 
            'post_type' => $cpt,
        ) );  
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
            <h2><?php the_title(); ?</h2>
    <?php endwhile;?>

最好使用$cpt这样的变量,并将自定义字段指定给它。不确定你在自定义字段中使用了什么插件,但我使用了ACF

$cpt = get_field('Your_post_type_name');
将$cpt放置在查询_帖子后,如下所示:

query_posts(array( 
    'post_type' => $cpt,
) );
    <?php 
    $cpt = get_field('your_selector');
        query_posts(array( 
            'post_type' => $cpt,
        ) );  
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
            <h2><?php the_title(); ?</h2>
    <?php endwhile;?>
它应该会起作用

所以它应该是这样的:

query_posts(array( 
    'post_type' => $cpt,
) );
    <?php 
    $cpt = get_field('your_selector');
        query_posts(array( 
            'post_type' => $cpt,
        ) );  
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
            <h2><?php the_title(); ?</h2>
    <?php endwhile;?>


perfect,我使用工具集类型,所以用
Types\u render\u field
替换了
get\u field
,它非常完美。perfect,我使用工具集类型,所以用
Types\u render\u field
替换了
get\u field
,它非常完美。