WordPress.org

Ready to get started?Download WordPress

Forums

Help with SQL query (1 post)

  1. rogerr
    Member
    Posted 6 years ago #

    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) :
    ?>

    Many thanks

    Rog
    popcornphotography.com.au

Topic Closed

This topic has been closed to new replies.

About this Topic