Custom Fields
Re-Envisioned
Support General Sort the results of rwmb_meta from a foreach

  • Creator
    Topic
  • #24026
    sagaroth
    Participant

    Hello everyone!

    I am currently developing a module for my site that will allow me to classify each solution to help a disability by type.
    Here’s an example:

    Type : Visual disability
    Solution : Add screen readers

    For this, I have my database in which these types and solutions are found. In this database, the solutions of one type or another are not in a defined order. They can be put at random, when a user adds one.

    I need to display, in a table, these types first (as a title), then the solutions corresponding to this type.

    I manage to generate a display thanks to a foreach loop, but my solutions are all mixed and therefore not clearly sorted.

    Here is how it is currently displayed

    Visual disability

    Audio-described cut-scenes

    Highlighted path to follow

    Sensitivity settings for all the controls

    Screen readers on menus

    Slow down the game speed

    But I would need it to look like this:

    Visual disability

    Audio-described cut-scenes

    Highlighted path to follow

    Screen readers on menus

    Slow down the game speed

    Physical disability

    Sensitivity settings for all the controls

    In my example above, only the solution “Sensitivity settings for all the controls” is part of the “Physical disability” type. The rest is part of the “Visual disability” type.

    Here is the code I currently use to retrieve my information from my database and display it. It is a WordPress associated with data coming from MetaBox.

    https://pastebin.com/embed_iframe/bxsuN2NW?theme=dark

    Thank you in advance for all the help you can give me!

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #24027
    Long Nguyen
    Moderator

    Hi,

    As I see in your code, you are trying to show the list of taxonomies name base on the option $accessibility_name and each taxonomy should belong to its parent when showing on the frontend.

    So I think you can use the argument 'hierarchical' => true when registering the taxonomy which has descendants like categories.

    Then use the field taxonomy or taxonomy_advanced to create select options for users to select type (term) and solution (child term) with the field type select_tree or checkbox_tree.

    After saving the option (taxonomy), you can use the function get_terms() to get all term (type) and child terms (solution) with the hierarchical as you want.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.