Support Log in

4. A/B Testing Meta Fields

Developer Guide
Prefer video? Watch the Rank Forge tutorials 9 short guides covering every feature Watch

Time-based meta title/description rotation fields. PRO feature.

Meta KeyTypeDescription
_rankforge_ab_enabledboolWhether an A/B test is currently active on this post.
_rankforge_ab_title_bstringVariant B title text. Variant A is the regular _rankforge_meta_title or template.
_rankforge_ab_desc_bstringVariant B meta description text.
_rankforge_ab_startint (timestamp)Unix timestamp when the test started. Used to calculate weekly variant rotation.
_rankforge_ab_currentstring ('a' or 'b')The currently active variant (recalculated on each page load).
_rankforge_ab_served_aintNumber of impressions (page loads) served for variant A.
_rankforge_ab_served_bintNumber of impressions (page loads) served for variant B.
php
// ----- Starting an A/B test programmatically -----

$post_id = 42;

update_post_meta( $post_id, '_rankforge_ab_enabled', true );
update_post_meta( $post_id, '_rankforge_ab_title_b', 'Alternative SEO Title for A/B Testing' );
update_post_meta( $post_id, '_rankforge_ab_desc_b', 'This is the alternative description being tested.' );
update_post_meta( $post_id, '_rankforge_ab_start', time() );
update_post_meta( $post_id, '_rankforge_ab_served_a', 0 );
update_post_meta( $post_id, '_rankforge_ab_served_b', 0 );
php
// ----- Reading A/B test status -----

$post_id = 42;

$enabled = get_post_meta( $post_id, '_rankforge_ab_enabled', true );
$variant = get_post_meta( $post_id, '_rankforge_ab_current', true );
$start   = (int) get_post_meta( $post_id, '_rankforge_ab_start', true );
$weeks   = floor( ( time() - $start ) / WEEK_IN_SECONDS );

$served_a = (int) get_post_meta( $post_id, '_rankforge_ab_served_a', true );
$served_b = (int) get_post_meta( $post_id, '_rankforge_ab_served_b', true );

// Calculate which variant should be active right now
$calculated_variant = ( $weeks % 2 === 0 ) ? 'a' : 'b';

// Stop A/B test and keep the winner
update_post_meta( $post_id, '_rankforge_ab_enabled', false );

Forge AI Assistant Online

Hi! I'm the Rank Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs