a_z_listing_get_posts_by_title( string $post_title, string $post_type = '' )

Retrive posts by title.


Description


Parameters

$post_title

(string) (Required) the title to search for.

$post_type

(string) (Optional) the post type to search within.

Default value: ''


Return

(array) the post IDs that are found.


Source

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

function a_z_listing_get_posts_by_title( $post_title, $post_type = '' ) {
	global $wpdb;

	$post_title = '%' . $wpdb->esc_like( $post_title ) . '%';

	if ( ! empty( $post_type ) ) {
		return $wpdb->get_results(
			$wpdb->prepare(
				"SELECT `ID`, `post_title` FROM `$wpdb->posts`
				WHERE `post_title` LIKE %s AND `post_type` = %s AND `post_status` = 'publish'",
				$post_title,
				$post_type
			)
		);
	} else {
		return $wpdb->get_results(
			$wpdb->prepare(
				"SELECT `ID`, `post_title` FROM `$wpdb->posts`
				WHERE `post_title` LIKE %s AND `post_status` = 'publish'",
				$post_title
			)
		);
	}
}

Changelog

Changelog
Version Description
2.1.0 Introduced.

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.