Support

Account

Home Forums General Issues Using get_field to set a variable with values from a user Reply To: Using get_field to set a variable with values from a user

  • Here’s the full code how I think it should work (but doesn’t!).

    <?php
    $post_id = "user_365";
    $userrignnumbers = get_field( 'ring_numbers', $post_id ); // Get all the 'released' bird ring numbers entered by this user 
    
    $args = array (
    	'post_type' => 'wglocations',
    	'posts_per_page'  => -1,
    	'category_name' => 'wg-finding',
    	'meta_query' => array (
    		array (
    			'key' => 'leg_ring_number',
    			'value' => $userrignnumbers, // Use the user's 'released' ring numbers
    			'compare' => 'IN', // Compare them to any 'found' ring numbers
    		)
    	)
    	);
    $query = new WP_Query ($args); // Output any matching 'found' entries
    	if ( $query -> have_posts() ) : ?>
    	<ul>
    	<?php while ($query -> have_posts () ) : $query->the_post(); ?>
    		<li><a href="<?php the_permalink() ?>"><?php the_field('leg_ring_number') ?> (<?php the_field('date') ?>)</a></li>
    	<?php endwhile; ?>
    	</ul>
    	<?php endif; 
    wp_reset_postdata(); ?>