Home Forums ACF PRO WP_Query Relationship values stored in Options


WP_Query Relationship values stored in Options

  • I scoured the forum but was unable to find someone asking the same question. I’ve created a Relationship field group in an Options page. In my template I’m trying to query those values/results but am not sure how to tell the server to grab the relationship field of “current_advertisers” from the list of options (‘option’).

    	// Randomly grab advertisers banners
    	$ids = get_field('current_advertisers', 'option', false, false);
    	$advertiser_query = new WP_Query(array(
    		'post_type' => 'advertiser',
    		'posts_per_page' => 2,
    		'post__in' => $ids,
    		'post_status' => 'any',
    		'orderby' => 'rand'
    	$current_advertisers = new WP_Query( $advertiser_query );
    	while ( $current_advertisers->have_posts() ) : $current_advertisers->the_post();
    	<div class="widget">
    		<a href="<?php the_field( 'website' ); ?>" title="<?php the_title(); ?>">
    			<?php the_post_thumbnail(); ?>
  • Hi @schmidty54

    Your code looks pretty simple, so I would debug it line by line to find out where it is going wrong.

    1. the get_field function does not contain 4 parameters, please remove one of the false

    2. You can debug a variable like so:

    echo '<pre>';
    		print_r( $ids );
    	echo '</pre>';
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘WP_Query Relationship values stored in Options’ is closed to new replies.