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
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?
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?
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