# redirection/4.3.2/actions/random.php

Redirection, version 4.3.2. 22 lines.

- Page: https://pluginprobe.com/plugins/redirection/4.3.2/code/actions/random.php
- Raw: https://pluginprobe.com/plugins/redirection/4.3.2/raw/actions/random.php
- Modified: 2019-03-02T13:08:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/redirection/4.3.2/code/actions/random.php#L10-L20`.

```php
<?php

include_once dirname( __FILE__ ) . '/url.php';

class Random_Action extends Url_Action {
	public function process_before( $code, $target ) {
		// Pick a random WordPress page
		global $wpdb;

		$id = $wpdb->get_var( "SELECT ID FROM {$wpdb->prefix}posts WHERE post_status='publish' AND post_password='' AND post_type='post' ORDER BY RAND() LIMIT 0,1" );
		return str_replace( get_bloginfo( 'url' ), '', get_permalink( $id ) );
	}

	public function process_after( $code, $target ) {
		$this->redirect_to( $code, $target );
	}

	public function needs_target() {
		return true;
	}
}

```
