WordPress.org

Forums

[resolved] WordPress displays wrong author (4 posts)

  1. jessor
    Member
    Posted 4 years ago #

    I have a multiuser blog and display author information in widgets. The code looks like this:

    if(!is_single()) {
            $return  = '<h3>Ansprechpartner</h3>';
            $return .= get_avatar(get_the_author_meta('user_email'), '70');
            $return .= get_the_author_posts_link() . '<br />';
            $return .= 'Telefon: ' . get_the_author_meta('telefon') . '<br />';
            $return .= '<a href="mailto:' . get_the_author_meta('email') . '">Email</a>';
        }

    Everything works fine *except* on this one page, it displays the wrong user. No matter what I set in the page editor, it always displays one specific user (not the first, not the latest user).

    I took a look in the posts table, the correct userid is set. Anyone seen this behaviour?

  2. jessor
    Member
    Posted 4 years ago #

    Found my problem. I use a shortcode on this page which lists posts and thus the widget shows the info for the last shown page.

  3. jessor
    Member
    Posted 4 years ago #

    For anyone who stumbles upon this.

    I did something like this:

    foreach($theposts as $thepost) {
        setup_postdata($thepost);
        $output .= '<li><a href="'. get_permalink($thepost->ID) . '">' . get_the_title($thepost->ID) . '</a></li>';
    }

    The problem is: setup_postdata does what it's supposed to do and changes the context of the current post or page. Since WordPress 3.0 there's a clean way to fix this: use wp_reset_postdata(); before you return the output.

  4. cmchristou
    Member
    Posted 3 years ago #

    Thank-you Jessor!

Topic Closed

This topic has been closed to new replies.

About this Topic