Home › Forums › General Issues › meta_key query with Post Object field › Reply To: meta_key query with Post Object field
hi,
i’m having the same problem. i can’t get my query to pull information that i’ve set up using a post object from a separate post type. i’m including the code below.
any help would be greatly appreciated. 🙂
<?php
global $post;
$args = array( 'post_type' => 'listing', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'sold_value', 'value' => 'Yes' ), array( 'key' => 'salesperson_name', 'value' => $salesperson = $_GET['salesperson'] ) ) );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
//Get the listing values
include (ABSPATH . 'assets/dealer-functions/dealer-functions.php'); ?>
<tr>
<td class="vehicle-year center"><?php echo $man_year; ?></td>
<td class="vehicle-title"><?php the_title(); ?></td>
<td class="vehicle-stock right"><?php echo $car_stock; ?></td>
<td class="vehicle-vin center"><?php echo $car_vin; ?></td>
<td class="vehicle-acquired center"><?php echo $car_regdate; ?></td>
<td class="vehicle-sold center"><?php echo $car_sale_date; ?></td>
<td class="vehicle-list right"><?php if(empty($car_list_price)) { echo 'No Price'; } else { ?><?php if (is_numeric($car_list_price)) { echo number_format($car_list_price, 2, '.', get_option('wp_thousandseparator')); } else { echo $car_list_price; } ?><?php } ?></td>
<td class="vehicle-base right"><?php if(empty($car_basecost)) { echo 'No Base'; } else { ?><?php if (is_numeric($car_basecost)) { echo number_format($car_basecost, 2, '.', get_option('wp_thousandseparator')); } else { echo $car_basecost; } ?><?php } ?></td>
<td class="vehicle-sale right"><?php if(empty($car_sale_price)) { echo 'No Price'; } else { ?><?php if (is_numeric($car_sale_price)) { echo number_format($car_sale_price, 2, '.', get_option('wp_thousandseparator')); } else { echo $car_sale_price; } ?><?php } ?></td>
<td class="vehicle-salesperson center"><?php if(!empty($get_salesperson)) { echo $car_salesperson; } else { echo 'None'; } ?></td>
</tr>
<?php endforeach; ?>
</table>
—-and—-
array (
'key' => 'field_5356425f36c39',
'label' => 'Salesperson Name',
'name' => 'salesperson_name',
'type' => 'post_object',
'post_type' => array (
0 => 'salesrep',
),
'taxonomy' => array (
0 => 'all',
),
'allow_null' => 1,
'multiple' => 0,
),
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.