Wordpress:查询页面自定义字段中给出的“category_name”

时间:2013-07-29 06:42:39

标签: php wordpress

我想查询页面自定义字段中指示的'category_name'中的帖子。换句话说,我可以使用自定义字段值填充下面的查询吗?

  <?php query_posts( array ( 'category_name' => '[from custom field]', 'posts_per_page' => -1 ) ); ?>
  <?php while (have_posts()) : the_post(); ?>
    ...
  <?php endwhile; ?>

有谁知道我会怎么做?任何帮助,将不胜感激。感谢。

1 个答案:

答案 0 :(得分:1)

如果我理解正确的话,这样的事情应该有效:

<?php 
$category_name = get_post_meta( $post->ID, 'custom_field_name', true );
query_posts( array ( 'category_name' => $category_name, 'posts_per_page' => -1 ) );
while (have_posts()) : the_post(); ?>
    ...
<?php endwhile; ?>