sanitize_title_for_query()WP 3.1.0

Sanitizes a title with the 'query' context.

Used for querying the database for a value from URL.

1 time — 0.000071 sec (very fast) | 50000 times — 0.90 sec (very fast)

No Hooks.

Return

String. The sanitized string.

Usage

sanitize_title_for_query( $title );
$title(string) (required)
The string to be sanitized.

Examples

0

#1 Examples of cleaning strings to use in a query.

// demonstration 
echo sanitize_title_for_query( 'hello world' ); // hello-world
// Preparing a string to be used in an SQL query
$parts = esc_sql( $parts );
$parts = array_map( 'sanitize_title_for_query', $parts );
$in_string = "'" . implode( "','", $parts ) . "'";
// Preparing a string to be used in an SQL query
$pagename = sanitize_title_for_query( wp_basename( $pagename ) );

Changelog

Since 3.1.0 Introduced.

sanitize_title_for_query() code WP 6.5.3

function sanitize_title_for_query( $title ) {
	return sanitize_title( $title, '', 'query' );
}