Skip to content

Conversation

@zippa71
Copy link
Contributor

@zippa71 zippa71 commented Nov 5, 2022

There are several drop down fields. Each subsequent one is filled from the parent by Term_ID using populate anything. In the feed settings, when using this code, you can not specify in which categories the product will be recorded.

Context

⛑️ Ticket(s): https://secure.helpscout.net/link/to/conversation

📓 Notion: https://notion.so/link/to/card

💬 Slack: https://slack.com/link/to/thread-or-message

Summary

There are several drop down fields. Each subsequent one is filled from the parent by Term_ID using populate anything.
In the feed settings, when using this code, you can not specify in which categories the product will be recorded.
@spivurno
Copy link
Contributor

spivurno commented Nov 6, 2022

Awesome, @zippa71!

Just want to make sure I understand...

  1. You have a handful of Drop Down fields.
  2. Each dropdown is populated (via Populate Anything) based on the term ID selected in the previous dropdown.
  3. This snippet will ensure that the post is added to all selected categories and not just the subcategory in the last field.
  4. This is required because the Advanced Post Creation add-on won't allow you to select more than one field to set terms from for a given taxonomy.

Is that right?

@zippa71
Copy link
Contributor Author

zippa71 commented Nov 8, 2022

Awesome, @zippa71!

Just want to make sure I understand...

  1. You have a handful of Drop Down fields.
  2. Each dropdown is populated (via Populate Anything) based on the term ID selected in the previous dropdown.
  3. This snippet will ensure that the post is added to all selected categories and not just the subcategory in the last field.
  4. This is required because the Advanced Post Creation add-on won't allow you to select more than one field to set terms from for a given taxonomy.

Is that right?

Good afternoon.
I had a problem.
There are about 10 First categories. Each category has children, and so on. Also, subcategories of different parents have the same names, but different Term_ID
Now further...
In the form of 4 drop-down lists.
The first gives only the main categories, the second depending on what is selected in the first, but this is possible only by Term_id , the third list from the second also by Term_id, etc.
You can add hiding logic, in general GP Populate Anything gives a lot of possibilities.
Now the problem I'm facing:
If you specify list fields in the feed, then when creating a product, a category with the term_ID number was created, if you specify a name, then the created product fell into the wrong hierarchy.

Using this code, the created product will fall into exactly those categories that are selected sequentially.
My question was asked here, but, unfortunately, no one responded.
https://stackoverflow.com/questions/72373859/gravity-form-does-not-correlate-correctly-when-publishing-a-post

PS
I want to pay attention, in each drop-down list, the Template looks like this:
Value -term_id
label-name

2022-11-08_14-17-24

…mental/gw-gfapc-map-multiple-fields-to-taxonomy.php
@spivurno
Copy link
Contributor

spivurno commented Nov 9, 2022

@zippa71 Thanks for the extra information. I've made some changes to the snippet to bring it inline with our Snippet Library standards (which I'm realizing aren't public 😅). Could you let me know if this is still working for you?

@zippa71
Copy link
Contributor Author

zippa71 commented Nov 10, 2022

Good afternoon.
term_ID array must be passed as integers, not as a string.
https://developer.wordpress.org/reference/functions/wp_set_object_terms/
For setting product categories, this code works. But I made changes because category IDs need to be passed as (int):
$taxonomy = 'product_cat';
$term_ids[] = (int)$entry[ $term_field_id ];

@zippa71 zippa71 closed this Nov 10, 2022
@zippa71
Copy link
Contributor Author

zippa71 commented Nov 10, 2022

@zippa71 Thanks for the extra information. I've made some changes to the snippet to bring it inline with our Snippet Library standards (

which I'm realizing aren't public 😅

). Could you let me know if this is still working for you?

I'm not very good at github, but I really want to help those who come across this problem. If you add this code to your collection, I will be very happy

@spivurno spivurno reopened this Nov 10, 2022
@spivurno
Copy link
Contributor

@zippa71 Looks like you may have closed the PR by accident. I've re-opened it and updated the snippet so that the term IDs are passed as integers. Good catch!

With that change, is the new version of this snippet working for you? Planning to merge this into the library as soon as I have your confirmation. 🙂

@zippa71
Copy link
Contributor Author

zippa71 commented Nov 11, 2022

@zippa71 Looks like you may have closed the PR by accident. I've re-opened it and updated the snippet so that the term IDs are passed as integers. Good catch!

With that change, is the new version of this snippet working for you?

Planning to merge this into the library as soon as I have your confirmation. 🙂
I confirm!

Good afternoon.
To summarize, this setting is only useful if you are passing field values as term _ID when selecting categories in GP Populate Anything. Then it allows you to find a category by term _ID and write a new product to the right place.

By the way, When I was looking for a solution to my problem, there was a similar request. Couldn't find it anywhere else.
https://community.gravityforms.com/t/advanced-post-creation-add-category/11013

@spivurno spivurno merged commit 5d4a7ae into gravitywiz:master Nov 11, 2022
@spivurno
Copy link
Contributor

Thanks for your contribution, @zippa71!

spivurno added a commit that referenced this pull request Oct 7, 2023
* Create gw-set-product-category.php

There are several drop down fields. Each subsequent one is filled from the parent by Term_ID using populate anything.
In the feed settings, when using this code, you can not specify in which categories the product will be recorded.

* Update and rename gravity-forms/gw-set-product-category.php to experimental/gw-gfapc-map-multiple-fields-to-taxonomy.php

* Update gw-gfapc-map-multiple-fields-to-taxonomy.php

Co-authored-by: David Smith <david@gravitywiz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants