I have five custom post types:
Persons (each record having a Title, first name, last name)
Show (each record having year perfomed, opening night, closing night and category taxnomy)
Position (each record being the name of a position such as Director, Designer, etc along with two different number fields which I will use for sorting in diferent situation)
Cast (title being the role acted in play, the person associated with playing the character and the associated Show the role was performed in)
Crew (the Crew Position Title, person’s name and associated show)
For Each Person, I have single layout lyaout which will show all the Shows that Person performed in as Cast member and then all the Shows that person worked as a Crew member on.
I am now trying to display all the Shows a person worked as a Crew member (all the records from the "crew" CPT when a "Crew" CPT field of "show" equal the Post Title of the CPT "show") BUT not display any "show" CPTs where that show record has the category of "Volunteers"
my current code is
// Get this person's post ID
$post_id = get_the_ID();
// Crew query
$crew_query = new WP_Query(array(
'post_type' => 'crew',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'techperson',
'value' => $post_id,
'compare' => '=',
),
),
'orderby' => 'meta_value_num',
'meta_key' => 'show', // Assuming 'show' is the meta field holding the related post title
'order' => 'ASC',
));
?>
<?php if ($crew_query->have_posts()) : ?>
<?php $crewshowID = get_field('show'); ?>
<h3>As Crew:</h3>
<ul class="castcrewlist">
<?php while ($crew_query->have_posts()) : $crew_query->the_post(); ?>
<?php $position = get_field('crewposition', $crewmember, false);
$positionname = get_the_title( $position); ?>
<?php $crewshowID = get_field('show', false, false); ?>
<li>
<em>
<a href="<?php echo the_permalink($crewshowID); ?>"><?php echo get_the_title($crewshowID); ?></a>
<?php $value = get_field("year", $crewshowID); ?>
<a href="<?php echo home_url('/past-seasons/?season=') . $value; ?>">
<?php echo '(' . $value . ')'; ?>
</a>
</em>
<strong><?php echo $positionname; ?></strong>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
the code I tried is:
// Get this person's post ID
$post_id = get_the_ID();
// Crew query
$crew_query = new WP_Query(array(
'post_type' => 'crew',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'techperson',
'value' => $post_id,
'compare' => '=',
),
),
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'volunteers',
'operator' => 'NOT IN',
),
),
'orderby' => 'meta_value_num',
'meta_key' => 'show', // Assuming 'show' is the meta field holding the related post title
'order' => 'ASC',
));
// Rest of the code remains the same
?>
<?php if ($crew_query->have_posts()) : ?>
<?php $crewshowID = get_field('show'); ?>
<h3>As Crew:</h3>
<ul class="castcrewlist">
<?php while ($crew_query->have_posts()) : $crew_query->the_post(); ?>
<?php $position = get_field('crewposition', $crewmember, false);
$positionname = get_the_title($position); ?>
<?php $crewshowID = get_field('show', false, false); ?>
<li>
<em>
<a href="<?php echo the_permalink($crewshowID); ?>"><?php echo get_the_title($crewshowID); ?></a>
<?php $value = get_field("year", $crewshowID); ?>
<a href="<?php echo home_url('/past-seasons/?season=') . $value; ?>">
<?php echo '(' . $value . ')'; ?>
</a>
</em>
<strong><?php echo $positionname; ?></strong>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
but it does not seem to be working. Any suggestions or tips to point me in the right direction?
2
Answers
actually if read from doc terms(int/string/array) but usually work for me if use array, try change to
‘terms’ => array(‘volunteers’),
get show post title without category volunteers
get all title show to array
load query crew cpt filter with meta value ‘show’ equals post title form cpt "show"