Nevermind, I solved it on my own. While reading on the WordPress Codex for $wpdb, I saw that if I use OBJECT_K
it will remove the duplicates and that solved my problem.
If it helps anyone, here is my working code:
function latest_posts_after_last_login( $atts ) {
global $wpdb, $current_user;
$atts = shortcode_atts( array( 'post_type' => ''), $atts, 'latest_posts_after_last_login' );
$post_type = $atts['post_type'];
$last_login = get_user_meta( $current_user->ID, '_last_login_for_posts', true );
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->posts.post_status="publish"
AND $wpdb->posts.post_type="%s"
AND $wpdb->posts.post_date > '%s'
ORDER BY $wpdb->posts.post_date DESC
";
$prepare = $wpdb->prepare($querystr, array($post_type , $last_login));
$pageposts = $wpdb->get_results($prepare, OBJECT_K);
foreach ($pageposts as $post) {
echo $post->post_title;
}
}
add_shortcode( 'latest_posts_after_last_login', 'latest_posts_after_last_login' );