Support

Account

Home Forums General Issues Link user to post but how to get post linked to user Reply To: Link user to post but how to get post linked to user

  • Hi, Not sure how your linking your posts so I am going to go on a limb and just give you some code you might be able to edit to get your data but note I could be way of due to not seeing your codes or having much to go on.

    I have not tested this so I might not have it all completely correct you will need to debug if not or change to suit your needs.

    
    // only fires when viewing currently logged-in user's profile page
    add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
    // only fires when viewing another user's profile page
    add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
    
    // you can add different actions for either of the above hocks
    
    //adding our function for calling on user profile both edit and show
    function my_show_extra_profile_fields($user_id) { 
    
    // get the users name as user field in ACF
    $user_d = get_user_by( 'id', $user_id )
    $nice_name_user = $user_d->username;
    
    //query for info of posts change to suit below
    query_posts(array(
        'orderby' => 'post_date' , 
        'post_type' => 'post or custom post name' , 
        'meta_key' => 'custom acf name', 
        'meta_value' => $nice_name_user ,
        'posts_per_page' => 100)
      );
    
    if (have_posts()) :
    while (have_posts()) : the_post();
    
    //echo out your info here
    echo'<p>'.get_field( "the acf name of filed to display from the post" ).'</p>';
    
    endwhile;
    endif;
    wp_reset_query(); 
    
     }