Support

Account

Home Forums Front-end Issues post object query not working

Unread

post object query not working

  • I am building a real estate site with a two CPTs (Listing and Agent) and ACFs. I have built a little plugin to add a shortcode on Listing CPTs that will show information from a Post Object field. On Listings I want the associated agent (that’s the post object field) with name (post title), headshot (featured image), and contact info (ACFs in the Agent CPT).

    The title and featured image are displaying correctly but the phone and email text fields are not displaying at all. I’m following the model code in the documentation. Here is my plugin code.

    <?php 
    /*
    Plugin Name: Agent Contact Box Shortcode
    */
    
    add_shortcode( 'gd_associated_agent', 'gd_associated_agent_relationship' ); // Add your shortcode here
    function gd_associated_agent_relationship() {
    	ob_start();
    	
    	$p = get_field('agent'); // Add your ACF field in here
    	if( $p ): ?>
    		
    	    <div style="width:49%;float:left;">
    		    <span class="agent-name"><a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a></span>HSB REALTY
    		    	
    		    
    
    		    <?php the_field('email'); ?>
    
    		    <?php the_field('phone'); ?>
    
    		</div>
    		<div style="width:49%;float:right;">
    			<?php if ( has_post_thumbnail()) : ?>
    			   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
    			   <?php echo get_the_post_thumbnail($p->ID,array(100,100) ); ?>
    			   </a>
    			<?php endif; ?>
    		</div>
    		<div style="clear:both;"></div>
    	<?php endif; ?>
    	
    	
    	<?php
    	return ob_get_clean();
    }
Viewing 1 post (of 1 total)

The topic ‘post object query not working’ is closed to new replies.