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

  • I took a look at the field groups. The user is not associated with either of the and the fields are not saved to the user in any way, as you said, they are saved to a custom post type.

    The other problem that I see is that on the “Release” post, there can be multiple ring numbers, either a comma separated list of in a repeater. This is going to be a problem to search.

    It would be easier to do the search when viewing the release page/post to search for the found pages/posts.

    // get ring numbers
    // $post_id is the post ID of the release page/post 
    // in the 'wglocations' post type
    // this first code is for the comma separated list
    $value = get_field('leg_ring_number', $post_id);
    // just in case they put spaces after commas, remove them
    $values = str_replace(' ', '', $ring_numbers);
    $ring_numbers = explode(',', $value);
    // now you have the values in the right format and
    // you can search for matching found numbers
    // the field on the leg_ring_number on post type wglocations
    // can only allow one number
    $args = array(
      'post_type' => 'wglocations',
      'posts_per_page' => -1,
      'category_name' => 'wg-finding',
      'meta_query' => array (
        array (
          'key' => 'leg_ring_number',
          'value' => $ring_numbers, // Use the user's 'released' ring numbers
          'compare' => 'IN', // Compare them to any 'found' ring numbers
    $query = new WP_Query ($args);
    // the rest of you code for displaying them continues here