Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save liranop/c92eb5506a0059adefd3ae59e541bf16 to your computer and use it in GitHub Desktop.
Save liranop/c92eb5506a0059adefd3ae59e541bf16 to your computer and use it in GitHub Desktop.
//
// https://developers.elementor.com/docs/hooks/custom-query-filter/
//
function custom_get_related_events($query) {
global $post;
// Get the custom field value for the current post
$meta_field = get_post_meta($post->ID, 'meta_field_name', true);
// CHANGE 'meta_field_name' !!!!!! to your relationship filed's name
if (!empty($meta_field) && is_array($meta_field)) {
// Modify the query to include related events
$query->set('post_type', 'events');
// CHANGE TO YOUR POST TYPE
$query->set('post__in', $meta_field);
$query->set('orderby', 'post__in');
}
}
add_action('elementor/query/my_relationship_custom_query', 'custom_get_related_events');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment