Php 如何在查询中添加回显?

Php 如何在查询中添加回显?,php,wordpress,custom-fields,posts,Php,Wordpress,Custom Fields,Posts,我试图在页面上显示某个类别的帖子,比如: <?php query_posts('category_name=category1'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 这很有效。但是,我希望“category1”取自页面的自定义字段。类似这样的情况(传入的代码不正确): 我怎样才能做到这一点呢?以这种方式使用它: $custom_c

我试图在页面上显示某个类别的帖子,比如:

<?php query_posts('category_name=category1'); ?>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

这很有效。但是,我希望“category1”取自页面的自定义字段。类似这样的情况(传入的代码不正确):


我怎样才能做到这一点呢?

以这种方式使用它:

$custom_cat_name = get_post_meta(get_the_ID(), 'custom_cat_name', TRUE);
query_posts('category_name=' . $custom_cat_name);
希望这有帮助

以这种方式使用它:

$custom_cat_name = get_post_meta(get_the_ID(), 'custom_cat_name', TRUE);
query_posts('category_name=' . $custom_cat_name);
希望这有帮助