• Hi!

    I’m doing a wp_query that lists all the offers in a page. The loop works fine.

    But I have a custom post type for all the shops and they have a custom field value which is the shop logo.

    So i have to get the logo from the shop custom post that is linked to offer post.

    When i try to do that i can get the linked logos to show but then the rest of the data is messed up.

    So inside the first query i try to do another query like this:

    $offer = get_post_meta($post->ID, 'wpcf-offer', true);
    $shop=$offer;
    $shop=strtoupper($shop);
    $ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE UCASE(post_title) LIKE '%$shop%' AND post_type='shop' AND post_status='publish'");
    if ($ids) {
      $args=array(
        'post__in' => $ids,
    	'post_type' => 'shop',
        'posts_per_page' => -1,
        'caller_get_posts'=> 1
      );
    
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post();
    	$logo = get_post_meta($post->ID, 'logo', true);?>
    		<div class="one_sixth logo">
    							<?php echo $logo; ?>
    						</div>
          <?php
      endwhile;
      } wp_reset_postdata();
    }

    But when i add this inside the first query it will just get the logos for each post but the content for the offers are all the same. The new content is the content of the page where i try to run the query.

    So how could i get the inner query just to return the logo and the rest of the data is from the offer post type? I hope u can get the point ??

Viewing 1 replies (of 1 total)
  • Thread Starter brutex

    (@brutex)

    And all the offers that doesn’t have the shop linked are working fine after that code.

Viewing 1 replies (of 1 total)
  • The topic ‘Get custom field value from other post’ is closed to new replies.