Support

Account

Forum Replies Created

  • Nevermind I got this to work 🙂

    <?php
    
    if ( have_rows( 'review_list_precontent', 'option' ) ) : 
        while ( have_rows( 'review_list_precontent', 'option' ) ) : the_row();
    
            if ( have_rows( 'page_content' ) ) : 
                while ( have_rows( 'page_content' ) ) : the_row();
    
    ?>
    
    <section>
    <?php get_template_part('partials/page-content/'. get_row_layout());?>
    </section>
    
    <?php
    endwhile; endif; 
    endwhile; endif;
    ?> 
  • Okay I got it to work! It seems like in my page.php template, calling this:

    
    while ( have_posts() ) :
    the_post();
    

    screwed it up.

  • Okay I have the 404 page set within settings > reading, and I think I’m like halfway to getting it working on the frontend. I have this code in the 404.php template:

    
    <?php 
    		
    $post_id = intval(get_option('error_page'));
    if (!empty($post_id)) {
    			
    $post = get_post($post_id);
    setup_postdata($post);
    get_template_part('page'); // this is the part where I think I have it wrong?
    exit; 
    }
    
    ?>
    

    The normal template that calls all of my flexible content rows is page.php so that’s why I set that in the line for get_template_part. However, it only reads the container div with empty content inside. (This code works on every other page just fine.) I know that just page.php isn’t technically part of a template, so maybe that’s why it doesn’t work? This is the content for that:

    
    <div id="page__content">
    
    		<?php
        $sectioncount = 0;
    		while ( have_posts() ) :
    			the_post();
    
    			// are there any rows within within our flexible content?
    	if( have_rows('page_content', $id )): 
            $sectioncount;
    		// loop through all the rows of flexible content
    		while ( have_rows('page_content', $id )) : the_row();
            $sectioncount++;
            
    
    ?>
    
            
            <?php get_template_part('template-parts/section', 'open');	?>
            
            
            
    			<?php	get_template_part('partials/page-content/'. get_row_layout());			?>
    			
    		<?php get_template_part('template-parts/section', 'close');	?>
    
    <?php
    			
    
    		endwhile; // close the loop of flexible content
    	endif; // close flexible content conditional
    
    			
    
    		endwhile; // End of the loop.
    	?>
    	
    	
    </div>
    

    See image attached for how it shows up on frontend. I really appreciate your help!

  • Brilliant! I didn’t even think of that. I’ve got the correct page set as “404 Page” with that code. Now the question is: how do I call this page’s content to display on the actual 404 page in the 404.php template?

  • So this is only possible if the flexible content is somewhere as a row on a page of the website, correct?

  • Dang I was so close, thank you! That seems to solve the error I was getting and it’s displaying the checkbox labels now, but it’s also displaying most of the classes as “unavailable” when they should be “available”.

    This one shows only one class as “available” when it should be all 7.

    <?php 
    $tier = get_field('tier');
    $values = $tier['available_features'];
    $field = get_field_object('tier_available_features');
    $choices = $field['choices']; 
    ?>
    
    <?php foreach($choices as $choice => $label) : ?>
    <?php foreach ( $values as $value ) : ?>
    <?php if( $value['value'] == $choice ) {		
        $status = 'available';
        }
        else {
        $status = 'unavailable';
        } ?>
    <?php endforeach; ?>
        <li class="<?php echo $status;?>"><?php echo $label;?></li>
    <?php endforeach;?> 

    This version lists the checkbox labels correctly but marks them all with the “unavailable” class.

    <?php 
    $tier = get_field('tier');
    $values = $tier['available_features'];
    $field = get_field_object('tier_available_features');
    $choices = $field['choices']; 
    ?>
    
    <?php foreach($choices as $value => $label) : ?>
    <?php if (in_array($value, $values)) {
        $status = 'available';
        }
        else {
        $status = 'unavailable';}?>
    							
    	<li class="<?php echo $status;?>"><?php echo $label;?></li>
    							
    <?php endforeach;?>

    What am I missing here to get it to appropriately return the value of the checkbox?

  • I have been trying to get this code to work but I keep getting an error “Trying to access array offset on value of type bool on line 110”. My checkbox field name is available_features and it is a sub field in a group name tier. I have tried both codes:

    Version 1:

    <?php
    $tier = get_field('tier');
    $values = get_field($tier['available_features']);
    $field = get_field_object($tier['available_features']); 
    $choices = $field['choices'];  // This is the line 110 that keeps throwing the error ?>
    
    <?php foreach($choices as $choice => $label) : ?>
    <?php foreach ( $values as $value ) : ?>
    <?php if( $value['value'] == $choice ) {		
           $status = 'available';
          }
       else {
           $status = 'unavailable';
       } ?>
    <?php endforeach; ?>
    <li class="<?php echo $status;?>"><?php echo $label;?></li>
    <?php endforeach;?> 

    Version 2:

    <?php
    $tier = get_field('tier');
    $values = get_field('available_features'); // This is the difference in V1 and V2
    $field = get_field_object('available_features'); // This is the difference in V1 and V2
    $choices = $field['choices']; // This is the line 110 that keeps throwing the error ?>
    
    <?php foreach($choices as $choice => $label) : ?>
    <?php foreach ( $values as $value ) : ?>
    <?php if( $value['value'] == $choice ) {		
           $status = 'available';
          }
       else {
           $status = 'unavailable';
       } ?>
    <?php endforeach; ?>
    <li class="<?php echo $status;?>"><?php echo $label;?></li>
    <?php endforeach;?> 

    I have also tried both with “get_sub_field” and “get_sub_field_object”. I keep running into the same error.

  • If I’m understanding correctly, you’ll need this:

    <?php
    
    $volunteer = get_sub_field( 'volunteer' );
    $register = get_sub_field( 'register' );
    
    ?>
    
    <?php if($volunteer): ?><button>Volunteer button</button><?endif;?>
    <?php if($register): ?><button>Register button</button><?endif;?>
    
  • I’m not sure I follow what you’re code is trying to do, but try this and see if it gets you the result you need:

    <?php 
    
    $gallery = get_field('event_gallery');
    
    ?>
    
    <div>
        <ul>
            <?php foreach( $gallery as $image ): ?>
                <li>
                    <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
                </li>
            <?php endforeach; ?>
        </ul>
    </div>

    Just make sure your field returns format as image array.

  • I swear I tried that and it didn’t work before. Thank you!

Viewing 10 posts - 1 through 10 (of 10 total)