I'm building a classified ad site and I want to display on the frontend and search results only ads from users who currently have an active subscription.
I checked the View's query filters, but I didn't see any operand that I could use to select only ads from users with an active subscription. Maybe I missed it. How would you do it?
Currently in my View's filter selections, I see only operands from Post Filters, Taxonomies, Theme Custom Fields and Toolset Custom Fields (my ad fields). I didn't see anything that would indicate a user is active or not. I haven't worked on the custom user fields with Toolset or installed my membership plugin yet. Could that be the reason I didn't see the operand?
Views is built on top of the built-in WordPress Class WP_Query, which is used by internal functions such as get_posts to query the database.
So what you can do with Views is dictated by what you can do with the WP_Query class.
When creating a query (or a View) to retrieve posts you can filter by standard post fields (from wp_posts), custom post fields (from wp_postmeta, which is where Types post fields are stored, the key having a prefix of 'wpcf-'), and taxonomies (from the taxonomy tables).
Filtering by anything else, such as user fields or data stored by 3rd party plugins in custom tables rather than as post meta, would require building custom queries with the required table joins. Views doesn't provide for that.
(You can also query users or taxonomies with Views, but here we are dealing with querying posts.)
So, turning to your question, you cannot filter posts by the status of the user.
I recommend you change the post status of the posts as required. By default only published posts will be displayed on the front-end, but you can create a View and add a filter for post status and choose which posts to display (e.g. if you want to present a user with a list of all their posts, unpublished and published).
So when the status of a user changes because their subscription expires, you would hook into that and change the status of their posts to draft or pending.
Instead of turning the post statuses of all published ads of a user whose subscription just expired into draft or pending, how about creating a new custom field called 'user_subscription_status' for the post?
When the user's subscription is still active, the value of that field is set to 'active'. When it expires, it's set to 'expired'. When it's canceled by user, it's 'canceled_user'. When it's canceled by admin, it's 'canceled_admin'. Would this work?
This way, when an ad is no longer published, I would know exactly why right away.
And it looks like I have to create this custom field for every ad custom post type I have.
As the subscription status seems to be closely linked to the membership functionalities, I guess I would need to ask MemberPress if I could add a hook when each of these subscription-related events occurs.
Yes, no reason why you couldn't use a post custom field to record the status instead of changing the post status, the key point being that it is the post that needs to store this, not the user.