Support

Account

Forum Replies Created

  • I did it from within the loop so, while not totally straightforward, allowed me to use get_field('participants'), and then foreach( $participants as $participant ) to access each user/participant associated with a given post as an array. From there I could get the user details.

    However, this is not going to work outside of the loop. You could try http://codex.wordpress.org/Class_Reference/wpdb to get specific meta_key values

    I think the following would return an array of all users (where the meta_key is ‘participants’). As users information is itself stored as an serialized array, you’d then need to dig into this.

    $metakey = 'participants';
    $participants = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );

    I’m pretty new to PHP so don’t bet your house on anything here, although I’ve successfully tried all the above. Best of luck

  • Tweaked the meta_query to add . '"' after $curauth->id to prevent some incorrect matches

    $args = array(
            'post_type' => 'post',
            'meta_query' => array(
    		array(
    			'key' => 'participants',
    			'value' => '"' . $curauth->id . '"',
    			'compare' => 'LIKE'
    		)
    	)
        );
        $wp_query = new WP_Query();
        $wp_query->query( $args );
    
        while ($wp_query->have_posts()) : $wp_query->the_post();
    
     get_template_part( 'partials/loop', 'resources' ); 
    
    endwhile; 
  • OK, replacing the original query with

     
    
    $args = array(
            'post_type' => 'post',
            'meta_query' => array(
    		array(
    			'key' => 'participants',
    			'value' => '"' . $curauth->id,
    			'compare' => 'LIKE'
    		)
    	)
        );
        $wp_query = new WP_Query();
        $wp_query->query( $args );
    
        while ($wp_query->have_posts()) : $wp_query->the_post();
    
     get_template_part( 'partials/loop', 'resources' ); 
    
    endwhile; 

    Appears to do the trick. Hope this helps anyone else in a similar bind. I will update this if anything breaks.

Viewing 3 posts - 1 through 3 (of 3 total)