In my own plugin I have a custom post type faq. In the admin listing are 14 faq posts. In the WordPress Settings under Reading is 10 posts per pages set. Additionally, I have added a pre_get_posts function with the following content.
function hep_pre_get_posts_faq(WP_Query $query)
{
// check if current query is not the main query
if (!$query->is_main_query()) {
return;
}
// edit the query only when post type is 'faq'
if (!is_admin() || $query->query['post_type'] == 'hep_faq') {
return;
}
// Protect against arbitrary paged values
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
// set pagination
$query->set('posts_per_page', 10);
$query->set('paged', $paged);
}
The list is displayed correctly with 10 entries. Where the pagination links are, there is written 14 items without pagination links. And this for a good reason, because if I force the display you see 1 of 1. But here should be 1 of 2 because there are 14 posts.
This already happened to me with another cpt. The strange thing here is that everything works fine on the live-system on the server. Only on the local development-system it doesn’t display the pagination links because of the same reason as described above.
Of course this confuses me a lot. As it seems not to be the code, because it’s exactly the same on the development system as on the live system.
I would be very happy for any help concerning this. The plugin is already live and is used productively by my customers.
Here are all query parameters:
Request
/wp-admin/edit.php
?post_type=hep_faq
Query String
post_type=hep_faq
&posts_per_page=20
Query Vars
cache_results 1
comments_per_page 50
lazy_load_term_meta 1
order DESC
paged 1
post_type hep_faq
posts_per_page 10
update_post_meta_cache 1
update_post_term_cache 1
and the custom post type arguments:
$args = array(
'label' => 'faq',
'description' => 'FAQ',
'labels' => $labels,
'supports' => array('title'),
'hierarchical' => false,
'capabilities' => $caps,
'public' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_menu' => 'hep-dashboard',
'show_in_admin_bar' => true,
'menu_position' => 1,
'menu_icon' => plugins_url() . "/img/contact.png",
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => array('hep_faq', 'hep_faqs'),
'map_meta_cap' => true,
'query_var' => true,
'rewrite' => array('slug' => get_option('hep_faq_slug')),
);