Skip to content

Meta query add faster compare modes#3293

Open
mehulkaklotar wants to merge 29 commits intoWordPress:trunkfrom
mehulkaklotar:meta_query_add_faster_compare_modes
Open

Meta query add faster compare modes#3293
mehulkaklotar wants to merge 29 commits intoWordPress:trunkfrom
mehulkaklotar:meta_query_add_faster_compare_modes

Conversation

@mehulkaklotar
Copy link
Member

@mehulkaklotar mehulkaklotar commented Sep 20, 2022

Adds the new LIKE based compare operators STARTSWITH, ENDSWITH, NOT STARTSWITH, NOT ENDSWITH to the meta query value compares.
They allow more performant and easier regular query cases than REGEXP which would be the alternative.

This PR is a fork from existing PR as contributor is temporarily unavailable to work on the changes.

Trac ticket: https://core.trac.wordpress.org/ticket/53450

Testing Instructions

  1. Create posts with meta listed below
  2. Create WP Meta Queries to get results
  3. Results should be according to meta query

Post 1 - Meta Key xyz - Meta Value abc

Meta Query:

new WP_Query(
	array(
		'update_post_meta_cache' => false,
		'update_post_term_cache' => false,
		'fields'                 => 'ids',
		'meta_query'             => array(
			array(
				'key'               => 'xyz',
				'value'             => 'abc',
				'compare'           => 'LIKE',
			),
		),
	)
);

Post 1 - Meta Key -> xyz - Meta Value abcstartswith
Post 2 - Meta Key -> xyz - Meta Value endswithabc
Post 3 - Meta Key -> xyz - Meta Value containsabccontains
Post 4 - Meta Key -> xyz - Meta Value pqr
Post 5 - Meta Key -> xyz - Meta Value abcabcabc

Meta Query:

new WP_Query(
	array(
		'update_post_meta_cache' => false,
		'update_post_term_cache' => false,
		'fields'                 => 'ids',
		'meta_query'             => array(
			array(
				'key'               => 'xyz',
				'value'             => 'abc',
				'compare'           => 'LIKE',
				'compare_like_mode' => 'startswith',
			),
		),
	)
);

Meta Query:

new WP_Query(
	array(
		'update_post_meta_cache' => false,
		'update_post_term_cache' => false,
		'fields'                 => 'ids',
		'meta_query'             => array(
			array(
				'key'               => 'xyz',
				'value'             => 'abc',
				'compare'           => 'LIKE',
				'compare_like_mode' => 'endswith',
			),
		),
	)
);

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

JanThiel and others added 29 commits June 18, 2021 17:48
…TARTSWITH, NOT ENDSWITH to the meta query value compares. They allow more performant regular query cases than REGEXP which would be the alternative.
…KE. Also extends this to key searches and adds testcases.
Implements DEV feedback
…m:JanThiel/wordpress-develop into 53450_meta_query_add_faster_compare_modes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants