Support

Account

Home Forums Front-end Issues Post Object: Selection does not show up in Custom Post Type Reply To: Post Object: Selection does not show up in Custom Post Type

  • Hi Jonathan,

    Yes the code is in banners.php which I’ve included in both single.php and single-company.php, thus I don’t see how come it doesn’t work on single-company.php but only on single.php 🙁

    If it please you here is the code in its entirety on banner.php:

    <?php if ( is_single() || is_singular() ) : // for singular items only ?>
    
    	<?php while ( have_posts() ) : the_post(); ?>
    
    		<?php $post_objects = get_field('banner_selection');?>
    		<?php if( $post_objects ):  // if banner selection was made, show those ?>
    			<?php foreach( $post_objects as $post): ?>
    				<?php setup_postdata($post); ?>
    				<?php get_template_part( 'banner','side' ); ?>
    			<?php endforeach; ?>
    			<?php wp_reset_postdata(); ?>
    
    		<?php else: // if there are no selected banners, show random 5 banners ?>
    			<?php query_posts( array ( 'post_type' => 'banner', 'meta_key' => 'banner_type', 'meta_value' => 'sidebar', 'posts_per_page' => 5, 'orderby' => 'rand' ) ); // The Query ?>
    				<?php while ( have_posts() ) : the_post(); // The Loop ?>
    					<?php get_template_part( 'banner','side' ); ?>
    				<?php endwhile; ?>
    			<?php wp_reset_query(); // End Query, RESET ?>
    		<?php endif; // end if banner selection was made ?>
    
    	<?php endwhile; ?>
    
    <?php else : // for homepage/archive items only ?>
    
    	<?php query_posts( array ( 'post_type' => 'banner', 'meta_key' => 'banner_type', 'meta_value' => 'sidebar', 'posts_per_page' => 5, 'orderby' => 'rand' ) ); // The Query ?>
    		<?php while ( have_posts() ) : the_post(); // The Loop ?>
    				<?php get_template_part( 'banner','side' ); ?>
    		<?php endwhile; ?>
    	<?php wp_reset_query(); // End Query, RESET ?>
    
    <?php endif; // is_single() ?>

    On your second point though, the code is outside the loop. This *could* be the case, however I still have no idea why it wouldnt work for single-company.php when it works for single.php.

    Many thanks in advance!