• Resolved orodruim

    (@orodruim)


    Hello.
    Some months ago I post a question in StackOverflow and you answer giving me some clues about what I wanted to do. This is the link:
    https://stackoverflow.com/questions/49277808/populate-a-select-from-another-in-wordpress-and-cf7

    Now, I am trying to implement what you told me, but I have no idea about to start the code.
    I would like to implement a select2 dropdown this way:

    – Pepper (parent)
    — Red (child)
    — Yellow (child)
    — Green (child)

    – Tomate
    — Cherry (child)
    — Cocktel (child)
    — Rama (child)

    How can I make something like this? The data are in DB (Table Crop, related with Table Variety (with a Crop_FK))

    Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    Hey sorry for the late reply, been on the move.

    In your form you need to create a dynamic drodown field (see screenshot #16). Now for the source of the drodown field options, you have 3 options presented to your (in the above screenshot the default Taxonomy Source is visible): ‘Taxonomy Source/Post titles/Filter.

    The data are in DB (Table Crop, related with Table Variety (with a Crop_FK))

    so this is where you have to take decision as to how you want to manage this data. If you need to make regular changes to your data (ie add/delete/rename) I would recommend to to map it as a WordPress Taxonomy, which you can then use as your source in the above field. Note, the change you make to the taxonomy moving fwd will not be synced with you custom tables, if this is required, you will need to implement a custom code to do this.

    On the other hand, if this data is static and does not change much, you can instead choose to map the data to your field using a custom filter (the last option in the field tag above). You will then need to construct manually your <option></option> html tag list using a [custom query](https://codex.www.ads-software.com/Class_Reference/wpdb) on your tables. In this case to achieve the specific list order, you will need to use option groups.

    Hope the above helps.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    I just released an update, along with a new screenshot (#17) on how to use the custom filter option to populate your dropdown.

    Thread Starter orodruim

    (@orodruim)

    Thanks you for your answer!
    I will test is as soon as i can, and i write you again with the results.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    Haven’t heard back from you, so I assuming you either fixed the issue or moved on. I am marking this as resolved. In case you still need some help, feel free to post a msg below.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using select2’ is closed to new replies.