I have a problem and I don't know how to solve it. I tried some solutions but I failed since I am not good programer. I also tried to find a solution, but there is no similar question asked. So... here is the problem.
I have a custom post type called "Arrangements", and one of the custom fields associated with that CPT is select box called "Nights" (rtm_nights), with options:
- no nights
- 1 night
- 2 nights
- 3 nights
In my single-arrangements.php there is a get_template_part function that call content-arrangements.php, and now I made 4 similar files, because I need to reorganize arrangements template:
- content-oneday.php
- content-twoday.php
- content-threeday.php
- content-fourday.php
Now... what do I need is to get some of these content templates depending of what is chosen in rmt_nights field.
- If "no nights" is chosen content-oneday.php should be called via get_tempalte_part.
- If "1 night" is chosen content-twoday.php should be called via get_tempalte_part.
- If "2 nights" is chosen content-threeday.php should be called via get_tempalte_part.
- If "3 nights" is chosen content-fourday.php should be called via get_tempalte_part.
I tried something like this in different versions but it is obviously a wrong approach:
<?php if ( get_post_meta($post->ID, 'rtm_nights', '3 nights') ) ; ?>
<?php get_template_part( 'content', 'fourday' ); ?>
<?php if ( get_post_meta($post->ID, 'rtm_nights', '2 nights') ) ; ?>
<?php get_template_part( 'content', 'threeday' ); ?>
<?php if ( get_post_meta($post->ID, 'rtm_nights', '1 night') ) ; ?>
<?php get_template_part( 'content', 'twoday' ); ?>
<?php if ( get_post_meta($post->ID, 'rtm_nights', 'no nights') ) ; ?>
<?php get_template_part( 'content', 'oneday' ); ?>
<?php endif; ?>