epl_elementor_preview_listing_id: choose the listing shown in the Elementor editor
Description #
When an EPL widget has no listing to show, for example while you design a template in the Elementor editor, EPL fills it with a sample listing. This filter picks which one.
The value starts as the epl_elementor_preview_id URL parameter (0 when there isn't one). EPL hooks this filter itself at priority 10: when the value is still 0 and you're editing an EPL Single Listing or EPL Listing Card template, it uses that template's Preview Listing ID setting.
The ID you return is only used when it's an EPL listing that is published, or one the current user can edit. Anything else (a draft, a private listing, a page) is ignored, so the URL can't be used to read unpublished listings. With no usable ID, EPL shows the newest published listing with a featured image (of the listing type the archive template targets, otherwise any EPL type), then the newest published listing.
It runs the first time a widget needs a sample listing in a request: in the Elementor editor or preview (a preview URL or Elementor AJAX request only counts for users who can edit_posts), or when a widget renders inside an EPL listing template without a listing. The result is kept for the rest of the request.
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_preview_listing_id', 'my_function', 20 );
Parameters #
$requested_id (int)
The requested listing ID. Default the epl_elementor_preview_id URL parameter, or the template's Preview Listing ID, or 0.
Examples #
Use listing 123 when neither the URL nor the template asks for one:
function my_epl_preview_listing( $requested_id ) {
return $requested_id ? $requested_id : 123;
}
add_filter( 'epl_elementor_preview_listing_id', 'my_epl_preview_listing', 20 );
Use a priority above 10 so EPL's own callback has already applied the template's Preview Listing ID.
Source #
lib/page-builders/elementor/class-epl-elementor.php, in EPL_Elementor::get_preview_property(). EPL's own callback is EPL_Elementor_Template_Router::filter_preview_listing_id(). Since 3.6.