• I tried to use the shortcode on a custom template page but it shows all the info like I posted [something] It doesnt make the shortcode conversion.

    tried this as well and nothing:

    <?php
      $user = get_user_by('slug', $author_name);
      echo get_wp_user_avatar($user->ID, 96);
    ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    https://www.ads-software.com/plugins/wp-user-avatar/

Viewing 3 replies - 16 through 18 (of 18 total)
  • I’m assuming this is a different comments table in your database than the one that WordPress creates. You’re getting the user ID for the avatar from here:

    $id=$row['Id_user'];

    Which means you have a column called Id_user in your comments table, correct?

    So, when you’re creating your comments, you’ll have to take the user ID of the logged-in user and save it to that column. Also, you should prevent users who aren’t logged in from being able to create comments, because then I’m guessing the comment is saving the Id_user with a 0. Alternatively, you could do something like this to allow non-registered users to leave comments, as long as they put an e-mail address:

    $id=$row['Id_user'];
    $email=$row['com_email'];
    $id_or_email = !empty($id) ? $id : $email;
    
    …
    
    get_wp_user_avatar($id_or_email, 40);

    But, initially you’ll need to pass the value of $idaccount to Id_user.

    Thread Starter Theopt

    (@theopt)

    Well, then I did all that already ?? so why its not working. because Im filling the DB with the values on idaccount.

    I guess I’m not following what you’re saying. The values for Id_user look correct in your database? Then the way you’ve written the query for the data is incorrect. I would probably rewrite your query like this:

    <?php
    global $wpdb;
    $comments = $wpdb->get_results(SELECT * FROM $wpdb->your_comments_table
    WHERE whatever_youre_looking_for = 'the_right_answer'
    ORDER BY date_column_perhaps);
    foreach($comments as $comment) { ?>
      <li class="panel" style="margin:10px; list-style-type: none;">
         <?php echo get_wp_user_avatar($comment->Id_user, 40); ?>
         <span class="com_name"><?php echo $comment->name; ?></span><br />
         <?php echo $comment->body; ?>
      </li>
    <?php } ?>
Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Shortcode not working’ is closed to new replies.