Support

Account

Home Forums General Issues Relationship Field in WP_Query Reply To: Relationship Field in WP_Query

  • <?php get_header(); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div id="service" class="leistungen before-hidden after-hidden-top">
    	<div class="pagepiling-container">
    		<article id="pagepiling">
    			<section class="pp-section" id="section1">
    				<div class="intro">
    					<h1><?php the_title(); ?></h1>
    					<div class="container-left">
    						<div class="wiper bottom-up">
    							<?php $images = get_field('sliderbox_links');
    							if( $images ): ?>
    							<?php foreach( $images as $key => $image ): ?>
    							<img src="<?php echo $image['url']; ?>" class="img <?php // echo $key==0 ? 'active':''; ?>" alt="<?php echo $image['alt']; ?>" />
    							<?php endforeach; ?>
    							<?php endif; ?>
    						</div>
    					</div>
    					<div class="container-right">
    						<div class="wiper top-down">
    							<?php $images = get_field('sliderbox_rechts');
    							if( $images ): ?>
    							<?php foreach( $images as $key => $image ): ?>
    							<img src="<?php echo $image['url']; ?>" class="img <?php // echo $key==0 ? 'active':''; ?>" alt="<?php echo $image['alt']; ?>" />
    							<?php endforeach; ?>
    							<?php endif;  ?>
    						</div>
    					</div>
    				</div>
    			</section>
    
    			<section class="pp-section pp-scrollable" id="section2">
    				<div class="overview">
    					<div class="content-box as-heading _fadeInBlock" style="background-image: url('<?php bloginfo('stylesheet_directory'); ?>/assets/img/section_header.png');" >
    						<div class="header">
    							<?php if( get_field('headline') ): ?>
    							<h1><?php the_field('headline'); ?></h1>
    							<?php endif; ?>
    							<?php if( get_field('subtitel') ): ?>
    							<p class="subhead">
    								<?php the_field('subtitel'); ?>
    							</p>
    							<?php endif; ?>
    						</div>
    					</div>
    
    					<div class="overview-text _fadeInBlock">
    						<?php the_content(); ?>
    					</div>
    
    					<div class="row btn-container _fadeInBlock">
    						<?php
    						$pages = get_pages( array(
    							'child_of' => $post->ID,
    							'sort_order' => 'asc',
    							'sort_column' => 'post_date')
    						);
    						foreach ( $pages as $page ) {
    							$post_slug=$page->post_name;
    							$btn = '<div class="col-lg-4 col-md-6">
    							<a href="#' . $post_slug . '" class="btn default"><span>';
    							$btn .= $page->post_title;
    							$btn .= '   </span></a>
    							</div>';
    							echo $btn; } ?>
    					</div> 
    				</div>
    			</section>
    
    			<?php
    
    			$args = array(
    				'post_type'      => 'page',
    				'posts_per_page' => -1,
    				'post_parent'    => $post->ID,
    				'order'          => 'ASC',
    				'orderby'        => 'menu_order'
    				);
    
    			$count = 2;
    			$subservice = new WP_Query( $args );
    
    			if ( $subservice->have_posts() ) : ?>
    			<?php while ( $subservice->have_posts() ) : $subservice->the_post(); $count++?>
    
    			<section class="pp-section" id="section<?php echo $count; ?>">
        <div class="fadearound">
            <div class="bgfadearound loading" style="background-image: url('<?php bloginfo('stylesheet_directory'); ?>/assets/img/bg_01.jpg');"></div>
            <div class="container-left">
                <div class="content-left">
                    <div class="content-box cb-big">
                        <div class="header">
                            <h1><?php the_title(); ?></h1>
                            <p class="subhead">
                                <?php if( get_field('subtitel') ): ?>
                                <?php the_field('subtitel'); ?>
                                <?php endif; ?>
                            </p>
                        </div>
                        <div class="description">
                            <?php the_content(); ?>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container-right">
                <?php 
    			$related_posts = get_field('reference_1');
    			if( $related_posts ): ?>
                <ul>
                    <?php foreach( $related_posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
                    <li>
                        <a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
                        <span>Custom field from $post: <?php the_field('author', $p->ID); ?></span>
                    </li>
                    <?php endforeach; ?>
                </ul>
                <?php endif; ?>
            </div>
        </div>
    </section>
    			<?php endwhile; ?>
    
    			<?php endif; wp_reset_query(); ?>
    
    		</article>
    	</div>
    </div>
    <?php endwhile; endif; ?>
    <?php get_footer(); ?>