• I want to include WordPress attributes in the data query to extract dynamic content

    For example:
    When users enter new data in a data project, their WordPress User ID will be logged in a separate column, and on an overview page, they will see a data table that displays only entries they have made and not from other users.

    In wordpress, it is possible to call the get_current_user_id() function, but this is not a query that I can call in WP Data Access as far as I can see. How would I be able to include this function in my query so my website displays dynamic content based on the logged in user?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @thhvancouver,

    Welcome to the forum! ??

    You can use the $$USERID$$ environment variable in your where clause and column default (for inserts) of your Data Projects. This has the same effect as using the get_current_user_id() function.

    The feature is documented here:
    https://wpdataaccess.com/docs/documentation/data-projects/user-roles-and-where-clauses/
    You might also want to checkout this page:
    https://wpdataaccess.com/docs/documentation/data-projects/managing-roles-and-user-access/

    Does this help?

    Best regards,
    Peter

    Thread Starter thhvancouver

    (@thhvancouver)

    Hi Peter,

    Thank you for the reply. Yes, thank you. A little comment on my side though: I cannot seem to search or edit data. If I try, an error message will appear saying that the page is not found. Is this a bug, or did I simply forget to turn a feature on?

    Thread Starter thhvancouver

    (@thhvancouver)

    Sorry, but the solution didn’t quite solve my problem after all: I created a custom user metadata field company_ID, and the company admin should be able to see data for their own company but none of the others. The company ID would use the WordPress function get_user_meta to call. Is there an equivalent for WP Data Access?

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @thhvancouver,

    Maybe you can you create a subquery that returns the company id from the usermeta table and use the $$USERID$$ environment variable and your meta key to query the usermeta table?

    >>> I cannot seem to search or edit data. If I try, an error message will appear saying that the page is not found. Is this a bug, or did I simply forget to turn a feature on?

    Some theme’s are using the same functions as the plugin and return an error if you try to edit your data. I released a new version of plugin yerterday which I hope will solve this issue, at least in most cases. Can you please update to WordPress 5.5 and WP Data Access 3.5.0 and try again?

    To be sure your project is configured correctly, it might be a good idea to test your application in the back-end before you test it on the front-end. If it does not work on the front-end you might consider using a different theme (if possible).

    Let me know if this works!

    Best regards,
    Peter

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to interact with wordpress user metadata’ is closed to new replies.