Skip Navigation

[Resolved] How to redirect the Single page to 404 Page Not Found page?

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 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.53 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Shane 6 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#627180

Hello...

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

Also how can I send the single page to the 404 error page programmatically? I found the following code from https://wordpress.stackexchange.com/questions/24891/redirect-restricted-page-to-404 :

  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();

Can I use the code above?

Thank you very much.

chris

#627396

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Chris,

Thank you for contacting our support forum.

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.

Please let me know.
Thanks,
Shane

#627602

Hello Shane,

Thanks for getting back to me.

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.

Thanks.

chris

#628411

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Chris,

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.

Thanks,
Shane