Support

Account

Home Forums Front-end Issues Match current user id to user relationship field Reply To: Match current user id to user relationship field

  • I tried another approach – I get all posts and than I filter those that is right into one array and all others into another array. Is in fact better for my purposes. I have this code:

    $arenden = new WP_Query( $args );
    if ( $arenden->have_posts() ) : 
        while ( $arenden->have_posts() ) : $arenden->the_post();
    $utfors_av = get_field('utfors_av');
    $utfors = reset($utfors_av);
    
        if($utfors == $user_id) {
            array_push( $idmina, get_the_ID() );}
        endwhile;
    endif;
    ?>

    The $args is just the standard, $idmina is the array I have setup were I want to store the IDs. But when I use this, I get an error:
    Warning: reset() expects parameter 1 to be array, boolean given in ../archive-arenden.php on line 42 Line 42 is $utfors = reset($utfors_av).

    When I use this on line 42 instead:
    $utfors = strstr($utfors_av, ',', true);
    I get another error saying it is an array.
    Warning: strstr() expects parameter 1 to be string, array given in /home/almewebb/alpnet/wp-content/themes/enterprise-pro/archive-arenden.php on line 42

    So what do I do wrong. Surely something trivial that I don’t see.