I want to implement landing pages in wordpress with A/B testing.

So each landing page should have two versions A and B. So if you visit landing page you should in 50% cases get version A and in other 50% cases should get version B.

So on 100 visits 50 times should be served version A and 50 times should be served version B. And of course one URL should serve both versions.

I started with this:

I have two custom post types: "landing-main" and "landing-versions".

The main page will be saved as "landing-main" post type and will have post meta fields which will contain ID's of A and B versions. A and B versions will be two different posts saved as "landing-versions" custom post type.

So I create version A and version B:

```
$args = array(
  'post_title'    => 'Version A',
  'post_content'  => 'Content of Version A',
  'post_status'   => 'publish', 
  'post_type'     => 'landing-versions',
 );

 $versionA_ID = wp_insert_post($args);

$args = array(
  'post_title'    => 'Version B',
  'post_content'  => 'Content of Version B',
  'post_status'   => 'publish', 
  'post_type'     => 'landing-versions',
 );

 $versionB_ID = wp_insert_post($args);

```

Then create the main post:

```
$args = array(
  'post_title'    => 'Main Post',
  'post_content'  => '',
  'post_status'   => 'publish', 
  'post_type'     => 'landing-main',
 );

 $main_ID = wp_insert_post($args);

```

Then add post meta to save versions A and B of main post:

```
add_post_meta($main_ID, 'first_version', $versionA_ID);
add_post_meta($main_ID, 'second_version', $versionB_ID);

```

Now suppose that URL of main post is:

```
www.mysite.com/?p=1

```

When you wisit this URL I want in 50% show content of version A and in 50% content of version B:

So I will add hook on conntent:

```
add_filter( 'the_content', 'changePostContent');

function changePostContent($content){
    global $post;
    if($post->post_type == 'landing-main'){

        $versionA_ID =get_post_meta($post->ID,'first_version',true);
        $versionB_ID =get_post_meta($post->ID,'second_version',true);

        $versionA = get_post($versionA_ID);
        $versionB = get_post($versionB_ID);

        $versionA_Content = $versionA->post_content;
        $versionB_Content = $versionB->post_content;

        // in 50% return $versionA_Content;
        // in 50% return $versionB_Content;
    }
}

```

So have anyone idea how to implement this part, in 50% return content of version A and in 50% return content of version B. Or this could be changed, fore example: in 70% return content of version A and in 30% return content of version B. So on 100 visits 70 times should be served content of version and and in other 30% should be returned content of version B