0
votes

I have a head-scratcher! I have a number of different post types, the default post/page/attachment + a handful created with the default CPT UI settings. Just one of them (articles) is misbehaving, with the WP_Query posts_per_page argument being ignored.

I cannot find anything about reserved post slugs, aside from the usual suspects mentioned above.

So, we have a bunch of post_type=articles. To test, I went into the DB and changed 3 of those to article - removing the s. Though I haven't created the post type in CPT IU, or in functions, WP_Query is able to return it... correctly no less!

            $a_articles__featured = array (
                'post_type'              => 'articles',
                'nopaging'                           => false,
                'posts_per_page'         => 2,
                'update_post_term_cache' => false,
                'update_post_meta_cache' => false
            );
            $q_articles__featured = new WP_Query( $a_articles__featured );

^^^ returns ALL posts with the CPTUI post_type of articles

            $a_articles__featured = array (
                'post_type'              => 'article',
                'nopaging'                           => false,
                'posts_per_page'         => 2,
                'update_post_term_cache' => false,
                'update_post_meta_cache' => false
            );
            $q_articles__featured = new WP_Query( $a_articles__featured    );

^^^ returns 2 posts with the manually adjusted post_type of article

            $a_articles__featured = array (
                'post_type'              => 'page',
                'nopaging'                           => false,
                'posts_per_page'         => 2,
                'update_post_term_cache' => false,
                'update_post_meta_cache' => false
            );
            $q_articles__featured = new WP_Query( $a_articles__featured    );

^^^ returns 2 posts with the default post_type of page

            $a_articles__featured = array (
                'post_type'              => 'events',
                'nopaging'                           => false,
                'posts_per_page'         => 2,
                'update_post_term_cache' => false,
                'update_post_meta_cache' => false
            );
            $q_articles__featured = new WP_Query( $a_articles__featured    );

^^^ returns 2 posts with the CPTUI post_type of events

Aside from just using article, which is a disruption in the URL, can anyone suggest trouble shooting from here?

Thank you!

1

1 Answers

0
votes

Update: I removed the CPT UI and went for the functional approach. Surprise surprise, it worked like a charm.

function custom_post_type_articles() {

$labels = array(
    'name'                => _x( 'Articles', 'Post Type General Name', 'cyprusprofile' ),
    'singular_name'       => _x( 'Article', 'Post Type Singular Name', 'cyprusprofile' ),
    'menu_name'           => __( 'Articles', 'cyprusprofile' ),
    'parent_item_colon'   => __( 'Parent Article', 'cyprusprofile' ),
    'all_items'           => __( 'All Articles', 'cyprusprofile' ),
    'view_item'           => __( 'View Article', 'cyprusprofile' ),
    'add_new_item'        => __( 'Add New Article', 'cyprusprofile' ),
    'add_new'             => __( 'Add New', 'cyprusprofile' ),
    'edit_item'           => __( 'Edit Article', 'cyprusprofile' ),
    'update_item'         => __( 'Update Article', 'cyprusprofile' ),
    'search_items'        => __( 'Search Article', 'cyprusprofile' ),
    'not_found'           => __( 'Not Found', 'cyprusprofile' ),
    'not_found_in_trash'  => __( 'Not found in Trash', 'cyprusprofile' ),
);

$args = array(
    'label'               => __( 'articles', 'cyprusprofile' ),
    'description'         => __( 'Articles', 'cyprusprofile' ),
    'labels'              => $labels,
    // Features this CPT supports in Post Editor
    'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
    // You can associate this CPT with a taxonomy or custom taxonomy.
    // 'taxonomies'          => array( 'genres' ),
    /* A hierarchical CPT is like Pages and can have
    * Parent and child items. A non-hierarchical CPT
    * is like Posts.
    */
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    // 'menu_position'       => 5,
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => false,
    'publicly_queryable'  => true,
    'capability_type'     => 'page',
);

// Registering your Custom Post Type
register_post_type( 'articles', $args );

}