wordpress sql posts query won’t display the latest post in a specific category

I’d suggest using the WP_Query() class for this one. Hopefully the below will help you –

<?php
$args = array(
    'category_name' => 'photography',
    'post_status' => 'publish',
    'post_type' => 'post',
    'posts_per_page' => 5
)
$work_items = new WP_Query($args);

if($work_items->have_posts()) : while($work_items->have_posts()) : $work_items->the_post()

        echo "<li>"; 
        echo "<a href="#" onClick='title_to_contents(".json_encode(get_the_title()).")'>";
        echo get_the_title(); echo "<span class="project_date">".get_the_time('Y')."https://wordpress.stackexchange.com/".get_the_time('M')."</span>";
        echo "</a>";
        echo "</li>";

    endwhile;
endif;
wp_reset_query();
?>