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

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

问题描述:

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

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

有没有人知道我该怎么做呢?任何帮助,将不胜感激。谢谢。

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

<?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; ?> 
+0

谢谢,流浪汉。正是我在找什么。 – aaronweber

+1

非常好。乐意效劳。 – Hobo