Home › Forums › General Issues › Meta query for post object? › Reply To: Meta query for post object?
So this thread has been very helpful! The answer @meandhim provided works great on all my pages, but I am unable to get this to work on my set Posts page – I am only assuming because it is having an issue w/ get_the_ID
Here is what i’ve got:
<?php
$ad_args = array(
'post_type' => 'ad',
'posts_per_page' => -1,
'orderby' => 'rand',
'meta_query' => array(
array(
'key' => 'ad_connected_pages',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
);
// query
$ad_query = new WP_Query($ad_args);
?>
<?php if( $ad_query->have_posts() ): ?>
<ul>
<?php while( $ad_query->have_posts() ) : $ad_query->the_post(); ?>
<li>
<a href="<?php the_field("ad_url"); ?>">
<?php $adIMG = get_field("ad_image"); ?>
<img src="<?php echo $adIMG['url']; ?>" />
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); ?>
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.