I created page category by this way ( or custom taxonomy with the help of ACF Extended Plugin). It works. Now I can add pages into category. My problem is that, I can not filter pages by category in admin dashboard.
1 Answer
What you show on the image is the post status, not a taxonomy.
But a filter already exists to do what you want. Go where you wrote your categories and on the right must be numbers. It's the number of post_type in each category. Click that number and you'll see the pages for the clicked category.
If you really want to add a filter, you can add a select
(for exemple) that you will write by using the hook restrict_manage_posts
<?php
function display_select_filter() {
global $post_type;
if ($post_type == 'my-custom-post-type') { // must change post_type to yours
$taxonomy = 'custom-tax'; // must change taxonomy to yours
$terms = get_terms(['taxonomy' => $taxonomy, 'hide_empty' => false]);
?>
<label class="screen-reader-text" for="<?= $taxonomy; ?>_filter"><?= esc_html__("Category", 'my-domain'); ?></label>
<select name="<?= $taxonomy; ?>" id="<?= $taxonomy; ?>_filter">
<option value=""><?php _e("All categories", 'my-domain'); ?></option>
<?php foreach ($terms as $k => $v): ?>
<?php $selected = (!empty($_GET[$taxonomy]) && $_GET[$taxonomy] === $v->slug) ? ' selected="selected"' : ''; ?>
<option value="<?= $v->slug; ?>"<?= $selected; ?>><?= $v->name; ?></option>
<?php endforeach; ?>
</select>
<?php
}
}
add_action('restrict_manage_posts', 'display_select_filter');
To work properly; you have to replace my-custom-post-type
with the slug of your post_type and custom-tax
by the name of your taxonomy.
-
thanks for your reply I added this into my function.php but not work @pierre Aug 25, 2021 at 11:48
-
But you helped me to understand what for I must search. I used this tutorial and worked. generatewp.com/filtering-posts-by-taxonomies-in-the-dashboard thank for everything Aug 25, 2021 at 11:53
-
1Thank you ! Normally, this code should work but it's true I didn't mention that you must replace with the name of your post_type and the name of your taxonomy (lines 3 & 4). I'll edit my message if it can help anybody ^^– Pierre RAug 26, 2021 at 6:13