Okay
  Public Ticket #2144751
MYSQL Data retrieval group concat filter
Closed

Comments

  • Richard Scholtens started the conversation

    Dear support,

    The table I created uses MYSQL code to retrieve text from the database. It retrieves values from multiple tables. These rows are referring to posts. Extra values are added from different tables with the post id as key. However, one table is called wp_levels which hold multiple values which are assigned to one post. I use GROUP_CONCAT to show all levels on one row. When I do this it also does it with the filter values. I want to show the values separate in the filter. 

    How do I do this?

    HOW IT IS NOW

    #####TABLE

    title      |     description      |     levels         |      date

    hello     |     world               |       A1, A2      |    01-01-2019

    bye       |     world                |       B1, B2     |    01-01-2019

    #### FILTER CHECKBOX

    A1

    A1, A2

    A2

    B1

    B1, B2

    B2

    HOW IT SHOULD BE

    #####TABLE

    title      |     description      |     levels                 |     date

    hello     |     world               |       A1, A2            |     01-01-2019

    bye       |     world                |       B1, B2         |     01-01-2019

    #### FILTER CHECKBOX

    A1

    A2

    B1

    B2


    #### IF B2 checked

    title      |     description      |     levels    |     date

    bye     |     world               |       B1, B2    |     01-01-2019

    #### MYSQL CODE AS IT IS NOW (NON RELEVANT CODE REMOVED)

    SELECT DISTINCT
        CONCAT('<a href="', wp_posts.`guid`, '">', wp_posts.`post_title`, '</a>') AS `Title`,
        wp_posts.`post_excerpt` `Description`,
        IFNULL(NULLIF(GROUP_CONCAT(DISTINCT wp_levels.`name` ORDER BY wp_levels.`name` ASC SEPARATOR ', '), ''), "Unspecified") `Levels`,
        wp_posts.`post_date_gmt` `Date`
    FROM wp_term_relationships
    INNER JOIN wp_posts ON wp_posts.`ID` = wp_term_relationships.`object_id`
    INNER JOIN wp_levels ON wp_levels.`post_id` = wp_posts.`ID`
    INNER JOIN wp_terms ON wp_terms.`term_id` = wp_term_relationships.`term_taxonomy_id` WHERE wp_term_relationships.`object_id` IN
        (SELECT DISTINCT wp_term_relationships.`object_id`
         FROM wp_term_relationships
         WHERE wp_term_relationships.`term_taxonomy_id`='19')
    GROUP BY wp_term_relationships.`object_id`

    I hope you guys can help me out.

    Sincerely,

    Richard Scholtens

  •  2,498
    Aleksandar replied

    Hello Richard.

    Thank you for your purchase.

    Can you access that column's settings, and go to Data. There, you should be able to change "Possible values for column" to "Define values list", where you could add these as individual values, so instead of "A1, A2, B1, B2, C1, C2" you can have "A1", "A2", "B1", "B2", "C1", "C2"...

    Please let me know if this works.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Richard Scholtens replied

    Hello Aleksandar,

    This was exactly the function I was searching for. I probably missed it because it was under Data instead of Filter. Thank you so much!


    Sincerely

    Richard Scholtens

  •  2,498
    Aleksandar replied

    You're welcome Richard

    Glad I could help.

    If you have any further questions or issues, please feel free to open a new ticket, and we'll gladly help.

    Best regards.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables