Okay
  Public Ticket #3170166
Functions in Placeholders
Closed

Comments

  •  2
    Rainer started the conversation

    We want to display a clients table in an intranet to logged in key account managers only.

    In the clients table we have a column "key-account-id"

    In the user table we also have the field "key-account-id"

    So we need a dynamic filter based on the "key-accound-id" of the logged in user.

    If we write a function like [get-key-account-id] to provide the key-account-id of the logged in user ....

    can we use this function as a placeholder to allow a dynamic query?

    e.g. %VAR1% = [get-key-account-id]

  • Sabri replied

    How can I get data from a different form.
    (For example user code from login.php file)
    I will use this data in SQL WHERE clause.
    $_POST["User_Code"]
    WHERE COMPANY_CODE = $_POST["User_Code"]

  •  1,688
    Miloš replied

    Hi, Rainer 

    Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.

    -

    There can be different ways to achieve predefined filters for our tables.

    -

    If you wish to try Pre-filtering tables through URL,  please check out this page with examples.

    -

    You can also use placeholders for table generation.

    1. For example, if you have a MySQL query-based table, you can use this query:

    SELECT * FROM yourDatabaseTable
    WHERE someColumn = %VAR1%

    %VAR1% can be defined in the Placeholders tab when you're creating a table, 

    then you can have multiple SQL Query-based tables that each have a different value filtered of that column.

    2. 

    Or, if you don't add the condition in an SQL query, you can add %VAR1% in column settings -> Filtering, under "Predefined filtering value".

    Then, you can have different versions of the same table, with the VAR1 value passed in the shortcode,

    let's say if we had a "Regions" column and we wish to filter a different region per each page.

    9385158392.png

    If we want page 1 for example only filtered for "Region A" , you can set predefined filter to this column as %VAR1% (filter type has to be set as text) :

    4266306375.png

    Then for a page where we need only Region 1 filtered, use shortcode [wpdatatable id=1 var1='Region A'] ,

    4565461533.png
    6779925578.png

     page 2 for only "Region B", shortcode would be [wpdatatable id=1 var1='Region B'] and so on, 

    to apply the values defined in the shortcode to the filter.

    ( This filtering method can be used for any table type, besides Simple Tables)

    -

    I also made a short video example - please check it out here.

    -

    In terms of getting the currently logged user ID, we have this placeholder :

    • %CURRENT_USER_ID% – this placeholder will be replaced with the ID of a currently logged-in user (if the user is logged in).

    -

    Let us know if that helped.  Thank you

    -


    @Sabri,

    I am sorry but i don't understand your use-case.

    Can you please check this documentation that shows all of our available Dynamic Placeholders for SQL Queries,

    and let me know if that helps?

    If not, can you please open a separate ticket about this subject and elaborate in more detail about your use-case,  and we will advise you if it is possible.

    Thank you

    Kind Regards, 

    Miloš Jovanović
    [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