Skip to content

Commit

Permalink
Merge pull request #14 from the-markup/fix-title-tests
Browse files Browse the repository at this point in the history
Improve the title test post selection logic
  • Loading branch information
dphiffer authored Dec 2, 2024
2 parents bdabcf7 + a5f8fb0 commit 2cbe302
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/TitleTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,22 @@ function check_variant_url_slugs($request_slug, $query) {
global $wpdb;

// Look up variant URL slugs that match the unknown request slug
$post_ids = $wpdb->get_col($wpdb->prepare("
SELECT post_id
FROM $wpdb->postmeta
WHERE meta_key LIKE 'title_variants_%_url_slug'
AND meta_value = '%s'
", $request_slug), 0);
if (empty($post_ids)) {
$post_id = $wpdb->get_var($wpdb->prepare("
SELECT pm.post_id
FROM $wpdb->postmeta AS pm, $wpdb->posts AS p
WHERE pm.meta_key LIKE 'title_variants_%_url_slug'
AND pm.meta_value = '%s'
AND pm.post_id = p.ID
AND p.post_status = 'publish'
", $request_slug));
if (empty($post_id)) {
return [];
}

// Replace the 'name' query with a list of IDs that have a variant slug
$query_vars = $query->query_vars;
unset($query_vars['name']);
$query_vars['post__in'] = $post_ids;
$query_vars['p'] = $post_id;

// We don't want this lookup query to be modified by the 'posts_results' filter
$this->ignore_post_variants = true;
Expand Down Expand Up @@ -530,8 +532,7 @@ function show_results_summary($post_id) {
* @return bool
*/
function is_single() {
$is_single = (is_single() && get_post_type() == 'post');
return apply_filters('split_tests_is_single', $is_single);
return apply_filters('split_tests_is_single', is_single());
}

}

0 comments on commit 2cbe302

Please sign in to comment.