CMB2 / cmb2-attached-posts

Custom field for CMB2 for attaching posts to a page.
GNU General Public License v2.0
135 stars 62 forks source link

Retrieving meta key value instead of ID #47

Closed anmamtl closed 7 years ago

anmamtl commented 7 years ago

Hello :)

Im using Attached posts with Field Ajax Search in Wordpress: https://github.com/rubengc/cmb2-field-ajax-search

From here, all is working. However, when trying to retrieve the artist name, it returns the ID instead of the name. How can I retrieve the name?

Thank you very much!

elisafern12 commented 7 years ago
<?php 
 $args = array( 
 'orderby' => 'title',
 'post_type' => 'catalogs'
 );
$the_query = new WP_Query( $args );
?>

<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();

$attached = get_post_meta( get_the_ID(), 'attached_artworks_in_catalog', true );

foreach ( $attached as $attached_post ) { 

  $price = get_post_meta( $attached_post, 'price', true );
  $artist = get_post_meta($attached_post, '_byd_artist_name', true );
  ?> 

  <div>
  <a href="<?php echo get_permalink($attached_post) ?>"> 
  <?php echo get_the_post_thumbnail($attached_post, 'catalog-thumb'); ?>
  <?php echo get_the_title ($attached_post)  ?> </a>
 <?php echo  $price ?>
 <?php echo $artist; ?>
</div>   

<?php } 
?>

<?php endwhile; else: ?> <p>Sorry, there are no posts to display</p> <?php endif; ?>
<?php wp_reset_query(); ?>
anmamtl commented 7 years ago

Got it, I just had to retrieve the title : <?php echo get_the_title ($artist); ?>

Closing.