I'm currently building an ad classified site with Toolset.
When a visitor tries to access the single page containing an ad whose poster no longer has an active subscription, I'd like to send the visitor to the Error 404 Page Not Found page.
I've created a PHP script that checks whether the poster of the to-be-viewed ad has an active subscription or not.
Can you please tell me which hook I should assign the script to? Is this hook part of View or Layout plugin? I looked around the documentation but I wasn't sure which plugin I should look into..
global $wp_query;
$wp_query->set_404();
status_header( 404 ); (or is it http_response_code(404); ? Which one is better?)
get_template_part( 404 );
exit();
Before we proceed , can you let me know how a post is marked as no longer active? Is it done using a custom field or is it that its done by the post status.
To answer your question, I'm using a custom field that I named 'qualified-membership' as part of my custom post type for my classified ads.
And then I have a 'listener' script that listens to the member's subscription activities (got it from MemberPress). For example, when they resume their subscription, my listener script would set the value of their ads' 'qualified-membership' fields in my postmeta database table to 'active'. If they cancel the subscription, it would set it to 'inactive'.
The script I just wrote for the single page would use its Post ID to find the value of its 'qualified-membership' field. If it's 'active', it would let it display the ad. If 'inactive', it would send the visitor to the 404 Page Not Found error page, but I don't know how to do that.
I hope I explained this well. Please let me know if you have any question.
I see what you're trying to achieve but this involves some effort for custom coding.
Unfortunately custom coding falls out of the scope of our support forum.
What I do recommend is that you can contact one of our registered contractors for a complete solution on this one https://toolset.com/contractors/
They will b e able to provide a much better solution than we can offer here.