a_z_listing_autocomplete_post_titles()

Ajax responder for A_Z_Listing_Widget configuration


Description


Source

File: widgets/class-a-z-listing-widget.php

function a_z_listing_autocomplete_post_titles() {
	global $wpdb;

	$post_title = '%' . $wpdb->esc_like( stripslashes( $_POST['post_title']['term'] ) ) . '%';

	$results = $wpdb->get_results(
		$wpdb->prepare(
			"SELECT `ID`, `post_title` FROM `$wpdb->posts`
			WHERE `post_title` LIKE %s AND `post_status` = 'publish'",
			$post_title
		)
	);

	$titles = array();
	foreach ( $results as $result ) {
		$titles[] = array(
			'value' => intval( $result->ID ),
			'label' => addslashes( $result->post_title ),
		);
	}

	echo json_encode( $titles );

	exit();
}

Changelog

Changelog
VersionDescription
2.0.0Introduced.

More Information

You are currently logged out. To view tickets you must first login.

I have read and understood the Terms of Service



User Contributed Notes

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.