sOliver
Member
Posted 4 years ago #
Hello,
I'm trying to fetch all category id's of posts that have a specific tag. How can I do that?
If anyone has a solution that would be awesome.
I need the ID's as an array to use wp_list_categories to exclude some categories.
I'm using that TDO plugin for intersection between tags and categories and thought that function tdotf_tag_cat_intersect could help me but it's pretty difficult.
Thanks for your help,
Oliver
sOliver
Member
Posted 4 years ago #
That's what I got so far .. but wordpress will stop the query, the site won't load properly.
I'm too stupid for wordpress what am I doing wrong ?
$catarray = array();
$tagids = "SELECT term_ID FROM $wpdb->terms WHERE name='$wo'";
$tagid = $wpdb->get_results($tagids, ARRAY_A);
while ($tagid){
$postid = $wpdb->get_var("SELECT object_id FROM $wpdb->term_relationships WHERE
term_taxonomy_id='$tagid'");
$postcat = $wpdb->get_var("SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE term_taxonomy_id='$postid'");
$checktax = $wpdb->get_var("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE
term_taxonomy_id='$postcat'");
array_push($catarray,$postcat);
}