A_Z_Listing::get_section( WP_Post|int $page )

Calculate the top-level section of the requested page


Description


Parameters

$page

(WP_Post|int) (Optional) The post object, or post-ID, of the page whose section we want to find.


Return

(WP_Post|null) The post object of the current section's top-level page.


Source

File: partials/class-a-z-listing.php

	protected static function get_section( $page = 0 ) {
		global $post;

		$pages = get_pages( array(
			'parent' => 0,
		) );
		$sections = array_map( function( $item ) {
			return $item->post_name;
		}, $pages );
		/**
		 * @deprecated Use a_z_listing_sections
		 * @see a_z_listing_sections
		 */
		$sections = apply_filters_deprecated( 'az_sections', array( $sections ), '1.0.0', 'a_z_listing_sections' );
		/**
		 * Override the detected top-level sections for the site. Defaults to contain each page with no post-parent.
		 *
		 * @param array $sections The sections for the site
		 */
		$sections = apply_filters( 'a_z_listing_sections', $sections );

		if ( ! $page ) {
			$page = $post;
		}
		if ( is_int( $page ) ) {
			$page = get_post( $page );
		}

		$section_object = self::find_post_parent( $page );
		$section_name = null;
		if ( $section_object === $page ) {
			$section_object = null;
		}

		if ( null !== $section_object ) {
			if ( isset( $section_object->post_name ) ) {
				$section_name = $section_object->post_name;
			} else {
				$section_name = null;
				$section_object = null;
			}
		}

		if ( AZLISTINGLOG ) {
			do_action( 'log', 'A-Z Section selection', $section_name, $sections );
		}

		if ( null !== $section_name && ! in_array( $section_name, $sections, true ) ) {
			$section_name = null;
			$section_object = null;
		}

		if ( AZLISTINGLOG ) {
			do_action( 'log', 'A-Z Section', $section_name );
		}
		return $section_object;
	}

Changelog

Changelog
Version Description
0.1 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.