A_Z_Listing_Indices::get_item_indices( array $indices, int|WP_Term $item, string $type )

Find and return the index letter for a post


Description


Parameters

$indices

(array) (Required) Previously discovered indices.

$item

(int|WP_Term) (Required) ID of the item whose index letters we want to find.

$type

(string) (Required) Type of listing - terms or posts.


Return

(array) The post's index letters (usually matching the first character of the post title)


Source

File: classes/class-a-z-listing-indices.php

	public static function get_item_indices( $indices, $item, $type ) {
		if ( 'terms' === $type ) {
			$title     = $item->name;
			$item_id   = $item->term_id;
			$permalink = get_term_link( $item );
		} else {
			$title     = get_the_title( $item );
			$item_id   = $item->ID;
			$permalink = get_the_permalink( $item );
		}

		$index = mb_substr( $title, 0, 1, 'UTF-8' );

		$indices[ $index ][] = array(
			'title' => $title,
			'item'  => ( 'terms' === $type ) ? "term:{$item_id}" : "post:{$item_id}",
			'link'  => $permalink,
		);

		if ( 'terms' === $type ) {
			/**
			 * Modify the indice(s) to group this term under
			 *
			 * @deprecated Use a_z_listing_item_indices
			 * @see a_z_listing_item_indices
			 */
			$indices = apply_filters_deprecated( 'a_z_listing_term_indices', array( $indices, $item ), '1.0.0', 'a_z_listing_item_indices' );
		} else {
			/**
			 * Modify the indice(s) to group this post under
			 *
			 * @deprecated Use a_z_listing_item_indices
			 * @see a_z_listing_item_indices
			 */
			$indices = apply_filters_deprecated( 'a_z_listing_post_indices', array( $indices, $item ), '1.5.0', 'a_z_listing_item_indices' );
		} // End if.

		/**
		 * Modify the indice(s) to group this item under
		 *
		 * @param array           $indices The current indices
		 * @param WP_Term|WP_Post $item The item
		 * @param string          $item_type The type of the item. Either 'posts' or 'terms'.
		 */
		$indices = apply_filters( 'a_z_listing_item_indices', $indices, $item, $type );

		/**
		 * Modify the indice(s) to group this item under
		 *
		 * @since 1.7.1
		 * @param array           $indices The current indices
		 * @param WP_Term|WP_Post $item The item
		 * @param string          $item_type The type of the item. Either 'posts' or 'terms'.
		 */
		$indices = apply_filters( 'a-z-listing-item-indices', $indices, $item, $type );

		if ( AZLISTINGLOG > 2 ) {
			do_action( 'log', 'Item indices', $indices );
		}

		return $indices;
	}

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.