Support

Account

Home Forums General Issues Taxonomy Field in Post Query? Reply To: Taxonomy Field in Post Query?

  • Yeah I couldn’t quite get that to work. I did play around some more with meta_query and I’m almost there. This is my current code:

    
    <div id="lorebook-archives">
        <?php // Only Show Current User's Posts
          if ( is_user_logged_in() ):
            global $current_user;
        wp_get_current_user();
    
        $universe = get_field('universe-selector');
    
        $author_query = array(
          'posts_per_page' => '-1',
          'author' => $current_user->ID,
          'post_type' => 'location',
          'meta_query' => array(
            array(
              'key' => 'location-universe',
              'value' => $universe
            )
          )
        );
    
        $author_posts = new WP_Query($author_query);
        while($author_posts->have_posts()) : $author_posts->the_post();
        ?>
    
          <?php
          $bg = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'full' );
          ?>
    
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
              <div id="archive-post" style="background: url('<?php echo $bg[0]; ?>') repeat center center #fbfbfb; background-size:cover;">
                <h1><?php the_title(); ?></h1>
              </div>
            </a>
    
        <?php
        endwhile;
      endif; ?>
    
      </div>
    

    I have a Post Object custom field on my page called “universe-selector”. I’m using this as a variable for the value of the “location-universe” field on the individual posts.

    I can’t get this to work with a Post Object field, though. I DID get it to work with a Relationship Field, by setting the Return Format to Post ID. But that option doesn’t seem to be available for Post Object fields, at least not in the free ACF v4. Is there any way I can get the Post ID from the Post Object field without requiring ACF Pro?