Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lechup opened this issue Feb 24, 2022 · 0 comments
Open

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

lechup opened this issue Feb 24, 2022 · 0 comments

Comments

@lechup
Copy link

lechup commented Feb 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant