[Resolved] Can you pass variable information to a view query?
The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.
Is it possible to setup a view's query so it can use variable data instead of just a string or a shortcode attribute? Specifically, I would like it to filter a custom post-type called "households" by showing only posts that have the custom field "household-usernames" equal to the currently logged in user. My website will be used for homeschooling and I would like both the mother and father to have separate accounts but be able to view and edit their family posts. One way I could think of to do this was to make the "household" post-type have a field called "household-usernames" that allowed multiple entries so that I could tag two usernames to the post instead of just one (the actual author). However, I cannot figure out how to actually get the view to query this way (household_usernames = currently_logged_in_username).
Alternatively (and this may be preferred), I thought of adding a custom user field called "master_user" and querying the views to show when a post's author is equal to the currently logged in user's "master_user" value. One user would be designated as the primary user and both users would have this person's username as the master_user field's value. However, I'm still stuck with the same question of how to translate this to a query using the built-in functionality of views (post author = currently logged in user's master_user field value).
Firstly, please note that you are posting in the Community Forum for users of the free Types plugin. As a Toolset customer you can and should post in the Technical Support forum which we prioritise and where you should receive speedier service.
The problem with what you describe is trying to use data from a user in a View which queries posts.
You can achieve this by passing the user field as a shortcode attribute which you then use in a Query Filter in the View.
You can then filter for a custom post field where the value comes from the 'username' shortcode attribute.
It may make sense to use the user ID instead of the user_login I used in the example, the key being that it needs to match what is stored in the post custom field.
Thanks! That seems to have done the trick. I will also switch to using User ID's instead of usernames - good thought. And thanks for clarifying the community vs support forums. I had not realized the difference. Cheers.
- Aaron
The forum ‘Types Community Support’ is closed to new topics and replies.