Support » Plugins » SQL SELECT ~ How to detect parent / children categories?

  • This code gives me all the categories, but how can I filter out parent / children?

    	$categories = $wpdb->get_results("
        SELECT DISTINCT(terms.term_id) as ID,, terms.slug, tax.description
        FROM $wpdb->posts as posts
        LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
        LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
        LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
        WHERE posts.post_status = 'publish' AND
        	posts.post_author IN ($author) AND
            tax.taxonomy = 'category'
        ORDER BY ASC
    echo $category->name;
  • The topic ‘SQL SELECT ~ How to detect parent / children categories?’ is closed to new replies.