0

I have several custom post types, here is the creation of two of them:

Projects

add_action( 'init', 'register_cpt_project' );

function register_cpt_project() {

$labels = array( 
    'name' => _x( 'Projects', 'project' ),
    'singular_name' => _x( 'Project', 'project' ),
    'add_new' => _x( 'Add New', 'project' ),
    'add_new_item' => _x( 'Add New Project', 'project' ),
    'edit_item' => _x( 'Edit Project', 'project' ),
    'new_item' => _x( 'New Project', 'project' ),
    'view_item' => _x( 'View Project', 'project' ),
    'search_items' => _x( 'Search Projects', 'project' ),
    'not_found' => _x( 'No projects found', 'project' ),
    'not_found_in_trash' => _x( 'No projects found in Trash', 'project' ),
    'parent_item_colon' => _x( 'Parent Project:', 'project' ),
    'menu_name' => _x( 'Projects', 'project' ),
);

$args = array( 
    'labels' => $labels,
    'hierarchical' => true,

    'supports' => array( 'title', 'editor', 'excerpt' ),
    'taxonomies' => array( 'project_categories' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,


    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => array('slug' => 'our-work/%project_categories%', 'with_front' => false),
    'capability_type' => 'post'
);

register_post_type( 'project', $args );
}

Leadership

add_action( 'init', 'register_cpt_leadership' );
function register_cpt_leadership() {

    $labels = array( 
        'name' => _x( 'Leaders', 'leadership' ),
        'singular_name' => _x( 'Leadership', 'leadership' ),
        'add_new' => _x( 'Add New', 'leadership' ),
        'add_new_item' => _x( 'Add New Leadership', 'leadership' ),
        'edit_item' => _x( 'Edit Leadership', 'leadership' ),
        'new_item' => _x( 'New Leadership', 'leadership' ),
        'view_item' => _x( 'View Leadership', 'leadership' ),
        'search_items' => _x( 'Search Leaders', 'leadership' ),
        'not_found' => _x( 'No leaders found', 'leadership' ),
        'not_found_in_trash' => _x( 'No leaders found in Trash', 'leadership' ),
        'parent_item_colon' => _x( 'Parent Leadership:', 'leadership' ),
        'menu_name' => _x( 'Leaders', 'leadership' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => true,

        'supports' => array( 'title', 'editor' ),

        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 20,

        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => false,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => array('slug' => 'who-we-are/leadership'),
        'capability_type' => 'post'
    );

    register_post_type( 'leadership', $args );
}

Everything is working great on the public site, but when you log into the wp-admin section, that's where things get weird.

The Leadership post type functions correctly. But the Projects type, when using the pagination buttons in the list page, returns no posts when going to any page greater than 1.

So if I go to: http://www.example.com/wp-admin/edit.php?post_type=project&paged=2

I get:

No projects found

Even though there are 70 posts, and the Screen Options are set to 20 posts per page. Yes, I can set that option to a higher number, and just show all posts in a single page, but that doesn't fix the problem at hand.

Has anyone had this issue before, or have any thoughts on how to fix this?

2
  • do you have anything hooked to modify queries on the front end, like pre_get_posts?
    – Milo
    Commented Oct 7, 2014 at 20:31
  • There are 3 instances of pre_get_posts in the functions file. Not sure what's the best method of posting those 3 functions since they won't work in the comments.
    – Joe
    Commented Oct 7, 2014 at 20:35

2 Answers 2

1

It turns out that in my functions.php file, I had the following function:

function limit_posts_per_archive_page() {
    if ( is_tax('project_categories') )
        $limit = 9999;
    else
        $limit = get_option('posts_per_page');
        set_query_var('posts_per_archive_page', $limit);
    }
add_filter('pre_get_posts', 'limit_posts_per_archive_page');

This was an old function modifying the pagination on the front-end, and it turns out that this was causing the error.

Removing the function fixed this.

0
-1

It's Permalinks issue. Please go to Appearance > Permalinks > set default first and than set post name. Than refresh your post you will be able to show your post content with it's title.

2
  • As the author answered himself that it was related to an old code he had, so looks like your answer is not relevant. Please edit your answer and explain why do you think your answer is correct.
    – Fayaz
    Commented Mar 18, 2017 at 7:38
  • I have checked this issue for many times it's relevant to permalinks. Commented Mar 18, 2017 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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