mantone
Member
Posted 5 years ago #
I'm trying to write a plugin, and I'm having a hard time going about it.
How would your write a query that searches the (POSTS)table for (ID) that contain post_mime_type of the value "image/jpeg"
I want to return the result into a
<li> list of some sort. One where I can possibly then display on a potential page of some sort.
Try something like this:
global $wpdb;
$tp = $wpdb->prefix;
$results = (array)$wpdb->get_results("
SELECT ID, post_title
FROM {$tp}posts
WHERE post_mime_type = 'image/jpeg'
ORDER BY post_title
");
if (count($results) > 0) {
echo '<ul>';
foreach ($results as $r) {
echo '<a href="' . get_permalink($r->ID) . '">' . $r->post_title . '</a>';
}
echo '</ul>';
}
(I just typed that out, so there may be bugs, etc.. but it should give you an idea at least)
mantone
Member
Posted 5 years ago #
Thanks, that was really helpful