OK I have a SQL query working well as follows:
<?php global $wpdb; $latest_posts = $wpdb->get_results('SELECT p.* FROM ' . $wpdb->posts . ' p LEFT JOIN ' . YAPB_TABLE_NAME . ' yi ON p.ID = yi.post_id WHERE p.post_type = \'post\' AND yi.URI IS NOT NULL ORDER BY RAND() LIMIT 0,' . $imagecount); $thumbConfig = array('h=150','w=150','q=100','fltr=usm|60|0.5|3'); //Change variables here ?>
What I need, is get the Parent Category Name included in the above query.
I have found the code below, which appears to be most of what I want but I have no idea how to add bit’s from below to the code above.
<?php global $wpdb; $categories = $wpdb->get_results("SELECT $wpdb->terms.term_id AS id, name, description from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE parent = '$cat' ORDER BY name ASC"); foreach($categories as $category) : ?>
- The topic ‘Help with SQL query’ is closed to new replies.