epl_elementor_directory_agent: pick the Staff Directory record for an agent

Description #

When the Staff Directory extension stores staff details in Directory posts, EPL's Elementor agent widgets find the agent by matching the username on the listing to each Directory post's property_staff_username. Imports can leave more than one Directory post with the same username. EPL picks the first one with a featured image, otherwise the oldest (lowest ID), so the editor and the live site always pick the same record. This filter lets you pick a different one.

It only runs when at least one published Directory post matches. Return a WP_Post; anything else means no agent at that position (the first position then falls back to the listing's author).

Part of the Elementor integration, which is in beta. See Elementor widgets and templates (beta) for how the widgets and templates fit together.


Usage #

add_filter( 'epl_elementor_directory_agent', 'my_function', 10, 3 );

Parameters #

$directory (WP_Post)
The Directory post EPL picked.

$posts (WP_Post[])
Every published Directory post with this username, oldest first.

$username (string)
The username saved on the listing.


Examples #

Use the newest matching record instead:

function my_epl_newest_directory_agent( $directory, $posts, $username ) {
	return end( $posts );
}
add_filter( 'epl_elementor_directory_agent', 'my_epl_newest_directory_agent', 10, 3 );

Source #

lib/page-builders/elementor/class-epl-elementor.php, in EPL_Elementor::get_directory_agent(), called from EPL_Elementor::get_listing_agent(). Since 3.6.