WordPress.org

Ready to get started?Download WordPress

Forums

get_post_meta Inside A Taxonomy Query? (3 posts)

  1. alanchrishughes
    Member
    Posted 2 years ago #

    Kind of weird to explain, but I am tagging basic WP posts by photographer (taxonomy).

    Then I have custom post type pages that serve as profile pages for these photographers and I want to query all the posts they have been tagged in on these pages.

    I thought it would be simple at first, that I could just enter the individuals name/taxonomy in a custom field and then use that custom field in the posts query like...

    <?php $loop = new WP_Query( array('photographer' => '
    
    echo get_post_meta($post->ID, 'PhotographerTax', TRUE);
    
    ', 'orderby' => 'title', 'order' => 'asc', 'posts_per_page' => 100 ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    
    <?php endwhile; ?>

    But something about trying to get_post_meta inside of a query jacks it all up. Any suggestions?

  2. alanchrishughes
    Member
    Posted 2 years ago #

    Would that even be possible since it is already inside some php?

  3. alanchrishughes
    Member
    Posted 2 years ago #

    Ahhh, you can all rest easy now, I some how pieced together the answer from scrapes of code I found

    <?php $loop = new WP_Query( array('photographer' => ''.get_post_meta($post->ID,'PhotographerTax',true).'' ) ); ?>
    
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    
    <?php endwhile; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.