• Hi all,

    I have a page template that has a conditional statement to use get_template_part() to pull in a different template based on an ACF field value. The code from both template part files works outside of the conditional statement, but not when used inside the conditional switch statement. Can anyone explain why this doesn’t work?

    Main Template code:

    	<main role="main">
    		<?php while( have_rows('add_content_block') ): the_row(); 
    			$blockSelector = get_sub_field('select_content_block');
    		?>
    
    		<?php 
    			switch ($blockSelector) {
    				case "Speaker Block":
    					get_template_part( 'content', 'speakers' );
    					break;
    				case "Events Block":
    					get_template_part( 'content', 'events' );
    					break;
    				default:
    					echo "Default";
    			}
    		?>
    
    		<?php endwhile; ?>
    
    	</main>

    [Large code excerpt removed by moderator per forum rules. Please use Pastebin or a Gist for all large code excerpts, they work better anyway. Seriously, we do not take removing user’s content lightly, we hate it actually. But no one can realistically help you by peering at your code through a tiny two-way scrolling box. Where ever you do post, turn on syntax highlighting if it’s available. TIA for your understanding.]

    • This topic was modified 7 years, 4 months ago by bcworkz. Reason: removed two complete template code
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Using get_template_part() and WP-Query’ is closed to new replies.