PHP Help. I want to display testimonials (entered as custom post types) in a loop of posts based on the service_area checkboxes on each service area page. For example Page-Area-1 will have checkboxes area-1 & area-2 selected: Page-Area-1 will then display all testimonials checked with either area-1 or area-2. The same custom field “service_area” is available in both the Page-Area-pages(city, ST) AND custom post type “Testimonials”. Make sense? Below is what I’m thinking for logic (need help with the syntax). I’m basing my current syntax on Example 3: http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/.
I think there is some confusion on calling the selected custom field (service_area) of the page vs. the selected custom field (service_area) of the testimonial posts. How do I pull the service_areas from the pages different than service_areas of the testimonial posts in order to match up the logic? (This would be similar to display posts of a particular category, but using checkboxes instead) Help?
<h2>Testimonials Near this Area</h2>
<?php
// args
$args = array(
‘numberposts’ => -1,
‘post_type’ => ‘testimonials’,
‘meta_query’ => array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘service_area’,
‘value’ => the_field(‘service_area’),
‘compare’ => ‘LIKE’
),
array(
‘key’ => ‘location’,
‘value’ => ‘Sydney’,
‘compare’ => ‘LIKE’
)
)
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class=”homeFeed” onclick=”location.href='<?php the_permalink(); ?>’;”>
“>
<h2><?php the_field(‘name’);?></h2>
from <?php echo the_field(‘service_area’);?>
<?php the_field(‘testimonial’);?>
</div>
<?php endwhile; else: ?>
<p><?php _e(‘Submit your testimonial today!’); ?></p>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>