• Hi all,

    I’m currently trying to write a plugin and i’m getting a little bug i can’t understand.

    I’m using wpdb to retrieve the author id (i’m running on wpmu but i think that that’s not a problem no?).

    This is my function:

    function getLastArticle($author){
    		//echo $author;
    		global $wpdb, $post;
    		$pre = $wpdb->prefix;
    		/*global $domain;
    		$author_id = $wpdb->get_var("SELECT user_id FROM wp_usermeta WHERE user_login = {$author} LIMIT 1");
    		$user_info = get_userdata($user_id);
    		//echo "Login: ".$user_info->user_login;
    		*/
    
    		/*$query = "SELECT ID from $wpdb->users WHERE user_login={$author}";
    		$author_id = $wpdb->get_var($query);
    		$wpdb->print_error();*/
    
    		$last_posts = (array)$wpdb->get_results("
    			SELECT ID, post_title, post_date
    			FROM wp_posts, wp_term_relationships, wp_term_taxonomy
    			WHERE post_author = 0
    			AND {$pre}term_relationships.object_id = {$pre}posts.ID
    			AND {$pre}term_relationships.term_taxonomy_id = {$pre}term_taxonomy.term_taxonomy_id
    			AND post_status = 'publish'
    			AND post_date < NOW()
    			AND post_type = 'post'
    			GROUP BY ID
    			ORDER BY post_date
    			LIMIT 5
    		");
    $liste = "<ul class=\"iapListPosts\"> |$author";
    
    		foreach($last_posts as $thepost){
    			$liste .= "<li><a href=\"".get_permalink($thepost->ID)."\">".$thepost->post_title."</a></li>";
    		}
    		$liste .= "$author_id</ul>";
    		return $liste;

    But it returns me absolutly nothing in the foreach, even the $author_id is null.
    I’m using a shortcode to display all the results.

    Any idea plase ?

  • The topic ‘wpdb to get user id -> problem’ is closed to new replies.