How do I separate media into displaying in specific categories on WordPress homepage?

Question

I have a site that has some custom code that pulls items from the media folder and displays them on the home page. We now want to possibly display the images pulled into specific category. How would I adjust this code to pull images into a stated category using the category name in the alt text of the image. Category name could be hard coded but would need to pull images dynamically.
Here is the code snippet:

get_header();
$media_query = new WP_Query(
array(
‘post_type’ => ‘attachment’,
‘post_status’ => ‘inherit’,
‘posts_per_page’ => -1,
)
);

posts as $post) {
echo ”;
if(strpos($post->post_mime_type, ‘image’) !== false){
echo ‘guid.'” alt=”‘ .$post->post_title. ‘”/>’;
}
else{
echo ‘post_title. ‘”/>’;
}
echo “” .$post->post_title. “”;
echo ‘guid. ‘” download=””>Download’;
echo “”;
}

Thank you

0
Omen1313 3 months 0 Answers 8 views 0

Leave an answer