Home Forums General Issues WP_Query on multisite is returning everything except get_field()


WP_Query on multisite is returning everything except get_field()

  • I am trying to query a category of posts from a post taxonomy called “A” into a multisite. The problem starts when The “$recent->ID” for every post is ==1 when i echo it… but if i echo “get_the_ID()” or “get_the_title()” or “get_permalink()”, it works fine. If i try to use get_field(), nothing comes through, and I think the reason might be tied to the fact that i can’t get $recent->ID to spit out the real ID.

    If i use get_post_meta(), I can see the fields coming through but the values are blank..

    BTW, I’ve used code like this in other areas of the site and it works fine. It’s just one particular place that it isn’t working (The theme used between parent and children multisite is the same, so they are all using the same functions.php taxonomies and post types).

      $rcount = 0;
      $brand = 'A';
      $args = array(
        'post_type' => 'post',
        'category_name' => 'blog',
        'posts_per_page' => 4,
        'tax_query' => array( array(
          'taxonomy' => 'brand',
          'field' => 'slug',
          'terms' => $brand,
      $recent = new WP_Query($args); 
      while($recent->have_posts()) : $recent->the_post();
        $name = get_the_title();
        $img = get_field('image-1'); // This isn't working...
        if($img == ''): $hideme = 'hideme2'; else: $hideme =''; endif;
        $link = get_permalink();
        echo '<li><a class="all" href="' . $link . '" target="_blank"><figure>'
          .'<span class="'. $hideme .'" style="background: url('. $img .') no-repeat;">'
          .'</span></figure><figcaption>'. $name .'</figcaption></a></li>';
      endwhile;							restore_current_blog(); ?>

    Any help you can provide in figuring out why I can’t use get_field() here would be greatly appreciated!

  • It works! My marketing director didn’t add the images to the fields…. should have checked that first. Doh..

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘WP_Query on multisite is returning everything except get_field()’ is closed to new replies.