Php 使用查询中的自定义字段/元键查询自定义帖子类型
我使用工具集类型设置了多个Wordpress自定义帖子类型,名称如下: no-9 八号 no-7 等等 我想做一个Wordpress查询,在另一个页面上显示来自这些自定义帖子类型之一的帖子。我想显示文章的页面还包含一个名为“issue no”的自定义字段,该字段与我想显示的自定义文章类型的名称相匹配 到目前为止,我的问题是: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
<?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
,它非常完美。