Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Created May 5, 2025 06:42
Show Gist options
  • Save Crocoblock/6d5f9c7a957fd9175ec99c1cb72a39de to your computer and use it in GitHub Desktop.
Save Crocoblock/6d5f9c7a957fd9175ec99c1cb72a39de to your computer and use it in GitHub Desktop.
JetEngine - fix for the Dynamic Link widget after Portfolio/Posts Elementor Pro widgets inside a listing item
<?php
class FIX_NESTED_POSTS {
private $object = null;
public function __construct() {
if ( ! function_exists( 'jet_engine' ) ) {
return;
}
$widgets = array(
'posts',
'portfolio',
);
add_action( 'elementor/frontend/widget/before_render', array( $this, 'before_element_render' ) );
add_action( 'elementor/frontend/widget/after_render', array( $this, 'after_element_render' ) );
}
public function needs_fixing( $element ) {
$widgets = array(
'posts' => true,
'portfolio' => true,
);
return isset( $widgets[ $element->get_name() ] );
}
public function before_element_render( $element ) {
if ( $this->needs_fixing( $element ) ) {
$this->object = jet_engine()->listings->data->get_current_object();
}
}
public function after_element_render( $element ) {
if ( $this->needs_fixing( $element ) && is_object( $this->object ) ) {
$this->object = jet_engine()->listings->data->set_current_object( $this->object );
}
}
}
new FIX_NESTED_POSTS();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment