johnbillion / extended-cpts

A library which provides extended functionality to WordPress custom post types and taxonomies.
GNU General Public License v2.0
974 stars 97 forks source link

Shared post_tag between CPT's and admin fillter tag=0 issue? #192

Open lechup opened 2 years ago

lechup commented 2 years ago

Hi, thanks for great tool, I'm haivng difficulties in generating simple admin filter based on post_tag taxonomy that I want to share across all my CPT's. Here is my news CPT:

<?php

add_action( 'init', function() {
    register_extended_post_type( 'news', [

        # Add the post type to the site's main RSS feed:
        'show_in_feed' => true,
        'has_archive' => true,
    'hierarchical' => false,

        # Add the post type to the 'Recently Published' section of the dashboard:
        'dashboard_activity' => true,

        # Add some custom columns to the admin screen:
        'admin_cols' => [
            'product_featured_image' => [
                'title'          => 'Obrazek',
                'featured_image' => 'thumbnail'
            ],
      'tags' => [
                'taxonomy' => 'post_tag'
            ],
            'ordering' => array(
                'title'       => 'Kolejność przy wyróżnieniu',
                'meta_key'    => 'ordering',
            ),
            'featured' => array(
                'title'       => 'Czy wyróżnione?',
                'meta_key'    => 'featured',
            ),
        ],

        # Add some dropdown filters to the admin screen:
        'admin_filters' => [
      'tags' => [
                'taxonomy' => 'post_tag',
            ],
            'featured' => array(
                'title'       => 'Czy wyróżnione?',
                'meta_key'    => 'featured',
            ),
        ],

    ], [
        # Override the base names used for labels:
        'singular' => 'Aktualność',
        'plural'   => 'Aktualności',
        'slug'     => 'aktualnosci',
    ] );

    register_taxonomy_for_object_type('post_tag', 'news');
} );

On admin panel I get basically what I want, but the problem is with default value of tag= when I pick show "all" tags, it's equal to =0 not empty string:

<select name="tag" id="filter_tags" class="postform">
    <option value="0" selected="selected">Wszystkie tagi</option>
    <option class="level-0" value="xxxx">xxxx</option>
    <option class="level-0" value="xxx">xxx</option>
</select>

So as a result any query through fillters that do not have tag selected results in empy query set because there is no tag with slug 0...