0

I saw a website let say example.com. Now there is a file called go.php. Whenever we go to example.com/go.php, we are redirected to a random post on that site. This happens everytime. That site is running Wordpress. Does anyone has an idea of:

  1. Where is go.php located??
  2. Possible code in go.php?

1 Answer 1

0

My guess would be that go.php is located in the root of the WordPress install.

The code in that fild would be something like this.

<?php require 'wp-config.php';

$post = get_posts([
    'post_type'      => 'post',
    'orderby'        => 'rand',
    'posts_per_page' => 1, 
]);

if (!empty($post)) wp_redirect(urldecode(get_permalink($post[0])));

This is a wild guess but it does the job.

This code gets one random post.
If found post, get the post permalink (url), decode the url (good if you use other languages besides english) and redirect to that post.

3
  • That's absolutely perfect! I just matched this with my condition and it's redirecting. But there's a problem. The first time, it redirects, second time too. For next attempts, it just stuck on the same post. Can you please explain why is this hapenning?
    – Aman Rawat
    Commented Sep 1, 2021 at 9:42
  • @AmanRawat How many times did you enter the go.php file. 'orderby' => 'rand' always gets a random post, it can give you the same post from time to time. if you run the php function rand(1, 10), you will sometimes get the same number back to back Commented Sep 1, 2021 at 9:44
  • OK, I got you. Thanks for the help, Buddy!☺☺☺☺
    – Aman Rawat
    Commented Sep 1, 2021 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.