2013-02-23 109 views
0

我有一个WordPress的博客,有一个自定义代码的主题,以访问类别的职位。直到现在我还没有使用过wordpress,并希望使这个代码适用于页面而不是帖子。到目前为止,我已经尝试了一些来自codex.wordpress.org的基本查询,但没有取得太大的成功。WordPress的按类别查询网页,并显示元信息

任何人都可以协助这个吗?

<?php $some_array_of_pages = new WP_Query(array('ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'category_name' => 'category' )); ?> 
    <?php while ($some_array_of_pages->have_posts()) : ?>  
    <?php $properties->the_post(); ?> 
<?php $meta1 = get_post_meta(get_the_ID(), 'meta_name', true); ?> 
<?php $meta2 = get_post_meta(get_the_ID(), 'meta_name', true); ?> 
<?php if ($meta1 && $meta2): ?> 
//do something here        
<?php endif; ?> 
    <?php wp_reset_postdata(); ?> 
    <?php endwhile; ?> 

回答

0

增加 'post_type' 到您的查询:

<?php $some_array_of_pages = new WP_Query(array('post_type'=>'page' )); ?> 

http://codex.wordpress.org/Class_Reference/WP_Query

完整的示例从OP:

<?php $some_array_of_pages = new WP_Query(array('ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'category_name' => 'category', 'post_type' => 'page' )); ?> 
+1

您好,感谢您回答这个问题对我来说。我试过你的答案,并没有返回任何结果。我假设这是因为该类别中没有页面? – user686483 2013-02-23 04:52:26

+0

这很可能。如果您想要,请尝试第一个查询。无论其他因素如何,它都会返回所有页面。 – 2013-02-23 04:53:13