Skip to content

Conversation

@jasonbahl
Copy link
Collaborator

@jasonbahl jasonbahl commented Feb 11, 2025

What does this implement/fix? Explain your changes.

This fixes a bug where updating child terms to have no parent was being prevented.

The bug was that we were using some if ( empty() ) checks vs if ( ! isset() ) checks.

So, when the ID 0 was passed for the parentId, it was bailing because it was "empty", even though it was set intentionally as 0 and 0 is a valid ID to set as the parent of a term.

Does this close any currently open issues?

closes: #3296

Any other comments?

Before:

Executing the updateCategory mutation on a child term, setting the parentId to "0" would not properly set the term's parent to 0, leaving the child category a child category instead of a top level category.

CleanShot 2025-02-11 at 20 24 53

Also, if we use an encoded id of term:0 (dGVybTow) that also does not work:

CleanShot 2025-02-11 at 20 26 24

After

Now, setting the parentId to "0" (or the encoded id for term:0 (dGVybTow)) properly updates the term to be a top-level term with no parent.

CleanShot 2025-02-11 at 20 28 23

CleanShot 2025-02-11 at 20 28 14

Additionally, we've also added the parentDatabaseId input as an option. So mutations can accept encoded Ids for parentId or the parentDatabaseId using the integer value. The docs for each field have been updated to indicate one or the other should be used but not both, and an error is returned if both are used.

…as 0 or no parent. Introduces `parentDatabaseId` as an optional field for hierarchical taxonomies and notes that either parentId or parentDatabaseId should be used, but not both.
@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 199bde2 and detected 0 issues on this pull request.

View more on Code Climate.

@jasonbahl jasonbahl self-assigned this Feb 12, 2025
@jasonbahl jasonbahl merged commit 3fa0972 into wp-graphql:develop Feb 12, 2025
38 checks passed
@kinnn2
Copy link

kinnn2 commented Feb 12, 2025

@jasonbahl It works perfectly.
Thanks so much as always.

@jasonbahl
Copy link
Collaborator Author

@kinnn2 thanks for confirming! Will get it released shortly 🙏🏻

@jasonbahl jasonbahl mentioned this pull request Feb 12, 2025
@coveralls
Copy link

Coverage Status

coverage: 83.023% (-0.005%) from 83.028%
when pulling 199bde2 on jasonbahl:fix/3296-term-update-prevents-parent-id-0-dev
into 558dc47 on wp-graphql:develop.

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

Successfully merging this pull request may close these issues.

Unable to change from mutation updateCategory to top level

3 participants