Skip to content

Instantly share code, notes, and snippets.

@propertyhive
Last active April 30, 2024 11:57
Show Gist options
  • Save propertyhive/0f4051f4c9698d610eab6e46ac6124ba to your computer and use it in GitHub Desktop.
Save propertyhive/0f4051f4c9698d610eab6e46ac6124ba to your computer and use it in GitHub Desktop.
Different single post elementor template based on meta
add_filter('template_include', 'custom_property_template_redirect', 99);
function custom_property_template_redirect($template) {
if (is_singular('property')) {
$department = get_post_meta(get_the_ID(), '_department', true);
if ('auction' === $department) {
$template_id = 123; // ID of your Elementor template for 'auction'
} else {
$template_id = 456; // ID of your Elementor template for others
}
$elementor_instance = \Elementor\Plugin::instance();
return $elementor_instance->frontend->get_builder_content_for_display($template_id);
}
return $template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment