开发者

display page of post depending on post type and custom field - wordpress

开发者 https://www.devze.com 2023-02-18 06:07 出处:网络
I\'m trying to display a page of post bas开发者_运维百科ed on the post type and custom field. This is what I have so far. It seems to display the posts only from the \'new\' post type how I\'d like b

I'm trying to display a page of post bas开发者_运维百科ed on the post type and custom field.

This is what I have so far. It seems to display the posts only from the 'new' post type how I'd like but now I'd like to also filter based on the custom field value and I'm not sure how.

<?php 
$args = array( 'post_type' => 'new', 'posts_per_page' => 10);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    the_title();
    echo '<div class="entry-content">';
    the_content()
    echo '</div>';
endwhile; ?>

Also I was wondering how I'd got about adding pagination to this.

Thanks!


You should be able to filter by custom fields (metas) with:

'meta_key=keyname&meta_value=meta_value'

Pagination with custom queries is nicely explained here: http://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号