[英]To display posts with a custom post type
i have create a custom post type, now i want display all the posts without the custom post type . 我已经创建了一个自定义帖子类型,现在我想显示所有没有自定义帖子类型的帖子。 I have display the custom post like this 我已经显示了这样的自定义帖子
$args = array(
'post_type' => 'badge',
);
// The query itself
$sb_user_query = new WP_Query( $args );
// The loop
while ( $sb_user_query->have_posts() ) : $sb_user_query->the_post();
$badge_id = $sb_user_query->post->ID;
$badge_title = get_the_title();
$author = get_the_author();
$author_id = get_the_author_ID();
$badge_image_small = get_the_post_thumbnail( $badge_id, array(16,16) );
$post_data = get_post_meta( $badge_id, '_metabox', true );
$comment_data = get_post_meta( $badge_id, '_comments', true );
echo $author.$badge_image_small;
endwhile;
now i want to display all the post type without the "badge" post type. 现在我想显示所有没有“徽章”帖子类型的帖子类型。 How can i do this please help me. 我该怎么做,请帮助我。
don't know what exactly you want , u can use get_posts() to fetch post 不知道您到底想要什么,您可以使用get_posts()来获取帖子
http://codex.wordpress.org/Template_Tags/get_posts http://codex.wordpress.org/Template_Tags/get_posts
Below is the link explained when to use get_posts(), query_posts(), WP_Query 下面是解释何时使用get_posts(),query_posts(),WP_Query的链接
https://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts/1755#1755 https://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts/1755#1755
I think below code will give u the idea.
<?php
$type = 'badge';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
global $post;
$badge_id = $post->ID;
$badge_title = get_the_title();
$author = get_the_author();
$author_id = get_the_author_ID();
$badge_image_small = get_the_post_thumbnail( $badge_id, array(16,16) );
$post_data = get_post_meta( $badge_id, '_metabox', true );
$comment_data = get_post_meta( $badge_id, '_comments', true );
echo $author.$badge_image_small;
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.