Elementor Pro widgets and templates enable us to add content quickly on WordPress pages. One of the better way of adding Elementor Widgets in pages is by saving them as template, add the query id custom query filter, and add the container using short code or template or better still even use WordPress hook to include the container on any WordPress page dynamically by calling its shortcode.
For example, this custom query filter ‘get_children’ will get the current page id filter the children pages for your widget added on the Elementor page.
This way, you don’t have to update every page for changes, just create one template of posts, add the query_id in Query section of widget, and add its shortcode on all Elementor pages to show children pages.
Simply add the following custom query filter snippet in your theme functions.php or use Code snippet plugin:
// Display children of current page in Posts Widget add_action( 'elementor/query/get_children', function( $query ) { $current_pageID = get_queried_object_id(); // Modify the query $query->set( 'post_parent', $current_pageID ); } );
And here is the gist link for get children snippet:
Similarly, to filter siblings of current page, simply add ‘get_siblings’ in query id of post widget by adding following code in your theme functions.php file or code snippet plugin:
// Display siblings of current page in Posts Widget add_action( 'elementor/query/get_siblings', function( $query ) { $current_pageID = get_queried_object_id(); // Modify the query $query->set( 'post_parent', wp_get_post_parent_id($current_pageID) ); } );
And here is the gist link for get siblings snippet:
Hope that helps.