If I am reading your code and description correctly, you can simplify that to:
$taxonomy = 'delivery_option';
$do = get_the_terms($post->ID,$taxonomy);
if (!empty($do) && !is_wp_error($do)) {
$do = array_shift($do); // assuming a single value as per the description.
$term = str_replace('-delivery','',$do->slug);
get_template_part('includes/sidebar-part',$term);
} else {
echo '<p>No custom include!</p>';
}
Note, I used WordPress’s get_template_part()
instead of PHP’s include()
as that is the more correct way to include template files.