Skip Navigation

[Resolved] Displaying Ads Only from Users with Active Subscription

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 2.41 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Nigel 6 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#618132

Hello,

I just have a question on using View's filters.

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?

Thanks.

#618135

Or maybe as soon as the user's subscription ends, the membership plugin would unpublish all their ads automatically?

Thanks.

#618278

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Chris

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.

#618521

Hi Nigel,

Thanks for the explanation. It makes sense.

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.

Thanks, Nigel, for your help.

#618667

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Chris

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.