wp-graphql / wpgraphql-acf

Re-architecture of WPGraphQL for ACF
GNU General Public License v3.0
83 stars 12 forks source link

Taxonomy field is resolving Category terms instead of custom taxonomy terms #177

Closed jasonbahl closed 7 months ago

jasonbahl commented 7 months ago

Description

When querying a field of the "Taxonomy" type, if terms of a custom taxonomy are saved to the field, they're not being returned as expected, instead terms of the "Category" taxonomy are being returned.

Steps to reproduce

  1. Activate the following PHP:
if (function_exists('acf_add_options_page')) {

    $args_dashboard_app = array(
        'page_title' => 'Dashboard App',
        'update_button' => __('Actualiser', 'acf'),
        'updated_message' => __("App mise à jour", 'acf'),
        'position' => '16',
        'icon_url' => 'dashicons-desktop',
    );
    acf_add_options_page($args_dashboard_app);

}

function add_custom_cpt_prevalet() {

    /* Programmes */

    $labels_programmes = array(
        'name' => _x('Programmes', 'JessicaPrevalet'),
        'singular_name' => _x('Programme', 'JessicaPrevalet'),
        'menu_name' => __('Programmes'),
        'all_items' => __('Tous les programmes'),
        'view_item' => __('Voir les programmes'),
        'add_new_item' => __('Ajouter un nouveau programme'),
        'add_new' => __('Ajouter'),
        'edit_item' => __('Editer le programme'),
        'update_item' => __('Modifier le programme'),
        'search_items' => __('Rechercher un programme'),
        'not_found' => __('Non trouvée'),
        'not_found_in_trash' => __('Non trouvée dans la corbeille'),
    );

    $args_programmes = array(
        'label' => __('Programme'),
        'description' => __('Tous sur programme'),
        'labels' => $labels_programmes,
        'supports' => array('title', 'editor'),
        'menu_position' => 10,
        'menu_icon' => 'dashicons-list-view',

        // Public CPT   
        'public' => false, // Ne pas rendre public
        'publicly_queryable' => true, // Rendre acessible en requete GraphQL
        'show_ui' => true, // Afficher dans le Back Office
        'show_in_menu' => true, // Afficher dans le menu du BO
        'query_var' => true,
        'rewrite' => false, // Désactiver la réécriture d'URL
        'capability_type' => 'post',
        'has_archive' => false, // Désactiver les archives
        'hierarchical' => false,

        // GraphGQL
        'show_in_graphql' => true,
        'graphql_single_name' => 'Programme',
        'graphql_plural_name' => 'Programmes',
    );

    register_post_type('programmes', $args_programmes);

}
add_action('init', 'add_custom_cpt_prevalet', 5);

function add_custom_taxonomies_prevalet() {

    /* Matériels */

    $labels_materiel = array(
        'name' => _x('Matériels', 'JessicaPrevalet'),
        'singular_name' => _x('Matériel', 'JessicaPrevalet'),
        'search_items' => __('Rechercher un matériel', 'JessicaPrevalet'),
        'all_items' => __('Tous les matériels', 'JessicaPrevalet'),
        'parent_item' => __('Matériel', 'JessicaPrevalet'),
        'parent_item_colon' => __('Matériel:', 'JessicaPrevalet'),
        'edit_item' => __('Modifier matériel', 'JessicaPrevalet'),
        'update_item' => __('Mise à jour matériel', 'JessicaPrevalet'),
        'add_new_item' => __('Ajouter un matériel', 'JessicaPrevalet'),
        'new_item_name' => __('Nouveau matériel', 'JessicaPrevalet'),
        'menu_name' => __('Matériel', 'JessicaPrevalet'),
    );

    $args_materiel = array(
        'hierarchical' => false,
        'labels' => $labels_materiel,
        'show_ui' => true,
        'public' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,

        'show_in_graphql' => true,
        'graphql_single_name' => 'Materiel',
        'graphql_plural_name' => 'Materiels',
    );

    register_taxonomy('materiel', array('programmes'), $args_materiel);

    /* Objectif */

    $labels_objectifs = array(
        'name' => _x('Objectifs', 'JessicaPrevalet'),
        'singular_name' => _x('Objectif', 'JessicaPrevalet'),
        'search_items' => __('Rechercher un objectif', 'JessicaPrevalet'),
        'all_items' => __('Tous les objectifs', 'JessicaPrevalet'),
        'parent_item' => __('Objectif parent', 'JessicaPrevalet'),
        'parent_item_colon' => __('Objectif parent:', 'JessicaPrevalet'),
        'edit_item' => __('Modifier objectif', 'JessicaPrevalet'),
        'update_item' => __('Mise à jour objectif', 'JessicaPrevalet'),
        'add_new_item' => __('Ajouter un objectif', 'JessicaPrevalet'),
        'new_item_name' => __('Nouvel objectif', 'JessicaPrevalet'),
        'menu_name' => __('Objectif', 'JessicaPrevalet'),
    );

    $args_objectifs = array(
        'hierarchical' => false,
        'labels' => $labels_objectifs,
        'show_ui' => true,
        'public' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'show_in_graphql' => true,
        'graphql_single_name' => 'Objectif',
        'graphql_plural_name' => 'Objectifs',
    );

    register_taxonomy('objectifs', array('programmes'), $args_objectifs);

    /* Figure */

    $labels_figures = array(
        'name' => _x('Figures', 'JessicaPrevalet'),
        'singular_name' => _x('Figure', 'JessicaPrevalet'),
        'search_items' => __('Rechercher une figure', 'JessicaPrevalet'),
        'all_items' => __('Toutes les figures', 'JessicaPrevalet'),
        'parent_item' => __('Figure parent', 'JessicaPrevalet'),
        'parent_item_colon' => __('Figure parent:', 'JessicaPrevalet'),
        'edit_item' => __('Modifier figure', 'JessicaPrevalet'),
        'update_item' => __('Mise à jour figure', 'JessicaPrevalet'),
        'add_new_item' => __('Ajouter une figure', 'JessicaPrevalet'),
        'new_item_name' => __('Nouvelle figure', 'JessicaPrevalet'),
        'menu_name' => __('Figure', 'JessicaPrevalet'),
    );

    $args_figures = array(
        'hierarchical' => false,
        'labels' => $labels_figures,
        'show_ui' => true,
        'public' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'show_in_graphql' => true,
        'graphql_single_name' => 'Figure',
        'graphql_plural_name' => 'Figures',
    );

    register_taxonomy('figures', array('programmes'), $args_figures);

    /* Niveaux */

    $labels_niveaux = array(
        'name' => _x('Niveaux', 'JessicaPrevalet'),
        'singular_name' => _x('Niveau', 'JessicaPrevalet'),
        'search_items' => __('Rechercher un niveau', 'JessicaPrevalet'),
        'all_items' => __('Tous les niveaux', 'JessicaPrevalet'),
        'parent_item' => __('Niveau parent', 'JessicaPrevalet'),
        'parent_item_colon' => __('Niveau parent:', 'JessicaPrevalet'),
        'edit_item' => __('Modifier niveau', 'JessicaPrevalet'),
        'update_item' => __('Mise à jour niveau', 'JessicaPrevalet'),
        'add_new_item' => __('Ajouter un niveau', 'JessicaPrevalet'),
        'new_item_name' => __('Nouveau niveau', 'JessicaPrevalet'),
        'menu_name' => __('Niveau', 'JessicaPrevalet'),
    );

    $args_niveaux = array(
        'hierarchical' => false,
        'labels' => $labels_niveaux,
        'show_ui' => true,
        'public' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'show_in_graphql' => true,
        'graphql_single_name' => 'Niveau',
        'graphql_plural_name' => 'Niveaux',
    );

    register_taxonomy('niveaux', array('programmes'), $args_niveaux);

    /* Zones corporelles */

    $labels_zones = array(
        'name' => _x('Zones corporelles', 'JessicaPrevalet'),
        'singular_name' => _x('Zone corporelle', 'JessicaPrevalet'),
        'search_items' => __('Rechercher une zone', 'JessicaPrevalet'),
        'all_items' => __('Toutes les zones', 'JessicaPrevalet'),
        'parent_item' => __('Niveau zone', 'JessicaPrevalet'),
        'parent_item_colon' => __('Niveau zone:', 'JessicaPrevalet'),
        'edit_item' => __('Modifier la zone', 'JessicaPrevalet'),
        'update_item' => __('Mise à jour la zone', 'JessicaPrevalet'),
        'add_new_item' => __('Ajouter une zone corporelle', 'JessicaPrevalet'),
        'new_item_name' => __('Nouvelle zone corporelle', 'JessicaPrevalet'),
        'menu_name' => __('Zone corporelle', 'JessicaPrevalet'),
    );

    $args_zones = array(
        'hierarchical' => false,
        'labels' => $labels_zones,
        'show_ui' => true,
        'public' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => true,
        'show_in_graphql' => true,
        'graphql_single_name' => 'ZoneCorporelle',
        'graphql_plural_name' => 'ZonesCorporelles',
    );

    register_taxonomy('zones_corporelles', array('programmes'), $args_zones);

}

add_action('init', 'add_custom_taxonomies_prevalet');
  1. Import the following ACF Field Group:

group_65ca430d37ca4.json.zip

  1. Create a few terms in the "niveaux" taxonomy:

CleanShot 2024-02-20 at 09 30 12

  1. Edit the "Dashboard App" ACF Settings page, adding content to the "Slides" flexible content field, choosing a term of a custom "niveaux" taxonomy:

CleanShot 2024-02-20 at 09 30 46

  1. Query for the Dashboard App:
query getDashboard {
  dashboardApp {
    appDashboard {
      slidesApp {
        ... on AppDashboardSlidesAppNiveauxRowLayout {
          fieldGroupName
          titre
          card {
            rubrique {
              nodes {
                __typename
                uri
                databaseId
                ... on Niveau {
                  id
                  databaseId
                  name
                  slug
                }
              }
            }
          }
        }
      }
    }
  }
}
  1. Expect: the Niveaux term 2" term returned for therubrique` field

  2. ACTUAL: The "uncategorized" term of the "Category" taxonomy is returned.

CleanShot 2024-02-20 at 09 32 30

PHP or JSON export of the ACF Field Group(s)

(see steps to reproduce)

Additional context

No response

WPGraphQL Version

1.21.0

WPGraphQL For ACF Version

2.1.1

ACF (Advanced Custom Fields) Version. Free or Pro?

6.2.4 PRO

WordPress Version

6.4.3

PHP Version

8.2

Additional enviornment details

No response

Please confirm that you have searched existing issues in the repo.

Please confirm that you have disabled ALL plugins except for WPGraphQL, WPGraphQL For ACF, ACF, etc.

jasonbahl commented 7 months ago

NOTE: this was reported in Slack and I created an issue to track it. I've successfully reproduced the bug following the steps outlined above.