Speakers::get_sessions_data( array $attr )

Fetches the relevant sessions and returns an array with speaker IDs and their corresponding tracks.


Parameters

$attr

(array) (Required) Array of attributes from shortcode.


Top ↑

Return

(array) An array containing the speaker IDs and their corresponding tracks.


Top ↑

Source

File: src/Conference/Views/Shortcode/Speakers.php

	public function get_sessions_data( $attr ) {
		// Fetch all the relevant sessions.
		$session_args = [
			'post_type'      => Plugin::SESSION_POSTTYPE,
			'posts_per_page' => 100,
		];

		/**
		 * Filters the session arguments for the speakers list shortcode.
		 *
		 * @since 1.0.0
		 *
		 * @param array<string|mixed> $session_args The session arguments.
		 * @param array<string|mixed> $attr         The shortcode attributes.
		 */
		$session_args = apply_filters( 'tec_schedule_manager_speakers_list_session_args', $session_args, $attr );

		// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_tax_query
		if ( isset( $attr['track'] ) && $attr['track'] !== [] ) {
			$session_args['tax_query'] = [
				[
					'taxonomy' => Plugin::TRACK_TAXONOMY,
					'field'    => 'slug',
					'terms'    => $attr['track'],
				],
			];
		}
		// phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_tax_query

		$sessions = get_posts( $session_args );

		// Parse the sessions.
		$speaker_ids     = [];
		$speakers_tracks = [];
		foreach ( $sessions as $session ) {
			// Get the speaker IDs for all the sessions in the requested tracks.
			$session_speaker_ids = (array) get_post_meta( $session->ID, 'tec_session_speakers', true );
			$speaker_ids         = array_merge( $speaker_ids, $session_speaker_ids );

			// Map speaker IDs to their corresponding tracks.
			$session_terms = wp_get_object_terms( $session->ID, Plugin::TRACK_TAXONOMY );
			foreach ( $session_speaker_ids as $speaker_id ) {
				if ( isset( $speakers_tracks[ $speaker_id ] ) ) {
					$speakers_tracks[ $speaker_id ] = array_merge( $speakers_tracks[ $speaker_id ], wp_list_pluck( $session_terms, 'slug' ) );
				} else {
					$speakers_tracks[ $speaker_id ] = wp_list_pluck( $session_terms, 'slug' );
				}
			}
		}

		// Remove duplicate entries.
		$speaker_ids = array_unique( $speaker_ids );
		foreach ( $speakers_tracks as $speaker_id => $tracks ) {
			$speakers_tracks[ $speaker_id ] = array_unique( $tracks );
		}

		return [
			'speaker_ids'     => $speaker_ids,
			'speakers_tracks' => $speakers_tracks,
		];
	}

Top ↑

Changelog

Changelog
Version Description
1.0.0 Introduced.