Support » Plugins » How would you write this query

  • Resolved mantone


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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)

    Thanks, that was really helpful

    No problem 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How would you write this query’ is closed to new replies.