extended-cpts icon indicating copy to clipboard operation
extended-cpts copied to clipboard

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

Open lechup opened this issue 2 years ago • 0 comments

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...

lechup avatar Feb 24 '22 12:02 lechup