• Resolved o2go

    (@o2go)


    Hello,

    I have a Custom Post Type called ‘modula-gallery’, where I added the relationship field ‘my_relatedcustomer’ to store a single user from selection.

    I can’t figure out how I can compare the related user to the wp_get_current_user();

    The code from this post https://docs.pods.io/tutorials/get-values-from-a-relationship-field/ seems suiting, but how would it work with relationship users?

    My goal is to have a php script that returns a clickable list of posts
    – where the post type is ‘modula-gallery’
    – where the current user is the same as the one selected in the relationshipfield called ‘my_relatedcustomer’

    I was also wondering: I extened a existing post type: Will there be data loss if the plugin that created ‘modula-gallery’ updates?

    I tried it for hours with query building, but I just don’t get it.

    Thanks a lot in advance.
    Warmly, o2go

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support Paul Clark

    (@pdclark)

    The following code will output a list of links from post type modula-gallery, skipping any content that does not have my_relatedcustomer equal to the current user:

    $q = new WP_Query([
    	'post_type' => 'modula-gallery',
    	'numberposts' => -1,
    ]);
    
    while( $q->have_posts() ) {
    	$q->the_post();
    	$related_customer = get_post_meta( get_the_ID(), 'my_relatedcustomer', true );
    	if ( (int) $related_customer['ID'] !== (int) get_current_user_id() ) {
    		continue;
    	}
    	?>
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br/>
    	<?php
    }
    wp_reset_postdata();
    
Viewing 1 replies (of 1 total)
  • The topic ‘Compare current user with user relationship of a post’ is closed to new replies.