Relationship and author ids

Support MB Relationships Relationship and author ids

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #43795
    JoeJoe
    Participant

    Hello,

    something very strange is happening in my oxygen editor, in a codeblock, i have this php code and a metabox relationship, i am on a single archive page that applies to archive -> authors ->all authors (the relationship is between user and CPT book)

    <?php
    $temp_id = get_the_author_meta('ID');
    echo 'Author ID before first query: ' . $temp_id;
    $connected = new WP_Query([
        'relationship' => [
            'id' => 'rs_book_usr',
            'to' => $temp_id,
        ],
        'nopaging' => true,
    ]);
    if ($connected->have_posts()) {
        while ($connected->have_posts()) : $connected->the_post();
            echo '<span>' . get_the_title() . '</span>';
        endwhile;
    }
    wp_reset_postdata();
    $temp_id = get_the_author_meta('ID');
    echo 'Author ID after first query: ' . $temp_id;
    ?>

    i want to display data from a user that is in relation with the cpt book, the code works, but for some reason the get_the_author_meta('ID'); value changes and the second code snippet gives wrong results. any ideas ?

    #43799
    PeterPeter
    Moderator

    Hello Joe,

    What happens if you remove the relationship code and its loop? Do you use the function get_the_author_meta() in a loop? If not, you have to add the user ID as the second parameter of this function.
    Following the WordPress documentation https://developer.wordpress.org/reference/functions/get_the_author_meta/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.