Support

Account

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(); ?>