Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Duplicate type registration errors when enabling field groups only on specific posts #198

Closed
benknight opened this issue Jan 5, 2021 · 6 comments
Labels
bug Something isn't working 🚀 Actionable

Comments

@benknight
Copy link

benknight commented Jan 5, 2021

My queries are still executing but when I enable debugging I see a huge list of "duplicate type" errors, which seems like my custom post type "component" is having its GQL types registered more than once.

See errors in example server GQL response: https://gist.github.com/benknight/baab7b0842694bff54e096835d727803

Here's how the post type is being registered:

function coracle__register_post_type() {
  register_post_type('component', [
    'exclude_from_search' => true,
    'graphql_single_name' => 'component',
    'graphql_plural_name' => 'components',
    'labels' => [
      'edit_item' => 'Edit Component',
      'name' => 'Components',
      'new_item' => 'New Component',
      'singular_name' => 'Component',
    ],
    'menu_icon' => 'dashicons-screenoptions',
    'menu_position' => 20,
    'public' => true,
    'rewrite' => [
      'slug' => 'browse',
    ],
    'show_ui' => true,
    'show_in_graphql' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => false,
    'supports' => ['custom-fields', 'title', 'revisions'],
  ]);
}

add_action('init', 'coracle__register_post_type');

Versions:

image

@benknight
Copy link
Author

Wrong repo.

@benknight
Copy link
Author

Re-opening, seems to be an issue with this ACF plugin (disabling plugin gets rid of the duplicate type registration errors).

@benknight
Copy link
Author

This might be a duplicate of #189

@benknight benknight changed the title Duplicate type registration errors when using custom post types Duplicate type registration errors when enabling field groups only on specific posts Jan 7, 2021
@benknight
Copy link
Author

Temporary solution (as described here #189 (comment)) is to assign the field group based on post type as opposed to specific posts.

@jasonbahl jasonbahl added this to the ACF Schema Location Rules milestone Mar 5, 2021
@jasonbahl
Copy link
Contributor

I've reproduced this with the following location rules:

Screen Shot 2021-03-05 at 2 45 26 PM

The issue here is that the field group is created and registered to the Post type in the Schema from the first rule, then the 2nd rule tries to register the field group to a specific post, and the plugin attempts to register it to the Post.

We've been discussing changing how location rules are handled, and instead of inferring location rules and mapping to the Schema the plan is to have a more explicit UI where users can define the specific Type(s) in the Schema where an ACF Field group should be available.

@jasonbahl
Copy link
Contributor

This is resolved by #250.

I can now create a field group that contains a "Link" field type, and assign it to Posts and Pages:

Screen Shot 2021-04-20 at 2 25 12 PM

Then query the field and get no debug message in the debug logs. No more "You cannot register duplicate Types to the Schema. The Type 'ACF_Link' already exists in the Schema. Make sure to give new Types a unique name." message.

Screen Shot 2021-04-20 at 2 25 02 PM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working 🚀 Actionable
Projects
None yet
Development

No branches or pull requests

2 participants