Custom post type has no pagination in backend
Question
I registered a custom post type like this:
function si_recipe_post_type()
{
$labels = array(
'name' => _x('Recipes', 'Post type general name', 'si-extend'),
'singular_name' => _x('Recipe', 'Post type singular name', 'si-extend'),
'menu_name' => _x('Recipes', 'Admin Menu text', 'si-extend'),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-list-view',
'show_in_rest' => true,
'supports' => array('title', 'editor', 'thumbnail', 'comments', 'excerpts', 'revisions', 'custom-fields'),
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'has_archive' => 'recipe',
);
register_post_type('recipe', $args);
}
add_action('init', 'si_recipe_post_type');
Then I added an overview to the backend, like this:
function set_custom_edit_recipe_columns($columns)
{
unset($columns['author']);
$columns['difficulty'] = __('Difficulty', 'si-extend');
$columns['custom_category'] = __('Category', 'si-extend');
return $columns;
}
add_filter('manage_recipe_posts_columns', 'set_custom_edit_recipe_columns');
function custom_recipe_column($column, $post_id)
{
switch ($column) {
case 'difficulty' :
$category_arr = get_field_object('difficulty', $post_id);
$choices = $category_arr['choices'];
$value = get_field('difficulty', $post_id);
if (!empty($value)) {
echo $choices[$value];
}
break;
case 'custom_category' :
$category_arr = get_field_object('category', $post_id);
$choices = $category_arr['choices'];
if (!empty($category_arr) && is_array($category_arr)) {
$print_str = "";
foreach ($category_arr['value'] as $value) {
$print_str .= $choices[$value] . " ";
}
echo $print_str;
}
break;
}
}
add_action('manage_recipe_posts_custom_column', 'custom_recipe_column', 10, 2);
The problem now is, I don’t have any pagination. I have 30 items, but the table in the backend only shows the first 8 and there is no pagination at the bottom. When I set the max number of posts shown per page to 999, I still only get 8. What do I have to do, to get the pagination?
0
2 years
2020-12-23T10:11:17-05:00
2020-12-23T10:11:17-05:00 0 Answers
9 views
0
Leave an answer