Support

Account

Home Forums Front-end Issues Relationships with cf "Post object" Reply To: Relationships with cf "Post object"

  • I find the solution!

    <?php 
    						/*
    						*  Query posts for a relationship value.
    						*  This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
    						*/
    
    						$buildings = get_posts(array(
    							'post_type' => 'novostroyki',
    							'meta_query' => array(
    								array(
    									'key' => 'ns_zastroyschik', // name of custom field
    									'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    									'compare' => 'LIKE'
    								)
    							)
    						));
    
    						?>
    						<?php if( $buildings ): ?>
    							<ul>
    							<?php foreach( $buildings as $building ): ?>
    
    								<li>
    										<?php echo get_the_title( $building->ID ); ?>
    
    								</li>
    							<?php endforeach; ?>
    							</ul>
    						<?php endif; ?>

    Thanks!