0

Every one knows the basic WordPress loop, every one knows that if you want just posts in a loop you put query_posts("post_type=post"); BEFORE the loop. which I have done.

The problem is I have a custom post type, called mini feeds, which shows up in my loop, the problem is, its the only thing that shows up. I have 60 posts, under post type posts and NONE of them show up, just this one (because there is currently only one) mini feed.

The custom post type looks like this:

public function aisis_mini_feed() {
    $labels = array(
        'name'                => _x( 'Mini-Feeds', 'Post Type General Name', 'text_domain' ),
        'singular_name'       => _x( 'Mini-Feed', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'           => __( 'Mini-Feed', 'text_domain' ),
        'parent_item_colon'   => __( 'Parent Mini-Feed:', 'text_domain' ),
        'all_items'           => __( 'All Mini-Feeds', 'text_domain' ),
        'view_item'           => __( 'View Mini-Feed', 'text_domain' ),
        'add_new_item'        => __( 'Add New Mini-Feed', 'text_domain' ),
        'add_new'             => __( 'New Mini-Feed', 'text_domain' ),
        'edit_item'           => __( 'Edit Mini-Feed', 'text_domain' ),
        'update_item'         => __( 'Update Mini-Feed', 'text_domain' ),
        'search_items'        => __( 'Search Mini-Feeds', 'text_domain' ),
        'not_found'           => __( 'No mini-feeds found', 'text_domain' ),
        'not_found_in_trash'  => __( 'No mini-feeds found in Trash', 'text_domain' ),
    );

    $rewrite = array(
        'slug'                => 'mini-feed',
        'with_front'          => true,
        'pages'               => false,
        'feeds'               => true,
    );

    $args = array(
        'label'               => __( 'mini-feed', 'text_domain' ),
        'description'         => __( 'Mini-Feed custom post type', 'text_domain' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_icon'           => 'http://icons.iconarchive.com/icons/fatcow/farm-fresh/32/folders-icon.png',
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => true,
        'publicly_queryable'  => true,
        'query_var'           => 'mini-feed',
        'capability_type'     => 'post',
    );

    register_post_type( 'mini-feed', $args );
}

My question?

  • Why is this mini feed showing up in my loop?
  • Where did the rest of my posts go?

My loop

query_posts("post_type=post");
if(have_posts()){
    while(have_posts()){
        the_post();
        the_title();
        the_content();
    }
}
1

At first, not everyone knows, but definetly should know, that there is a pre_get_posts hook which should, in most cases, be used instead of query_posts.

Further, defining only one custom post type results in bringing just one custom post type. It's correct. When one want to bring both, custom post type and posts, one should use the abbility of post_type param acceptiong array, not only string. Thus, try this code:

function show_mini_feeds_on_home( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_type', array('post', 'mini-feed') );
    }
}
add_action( 'pre_get_posts', 'show_mini_feeds_on_home' );
  • +1 for "At first, not everyone knows, but definetly should know..." – s_ha_dum Feb 24 '13 at 0:03
  • this is NOT what I want, why? because it adds mini feeds to the main query of posts. when I specifically said I did NOT want this custom post type in the main query for posts >.> Also this function did nothing as My mini feeds STILL show up but my posts DO NOT. – TheWebs Feb 25 '13 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.