WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get terms based on posts that are in a custom taxonomy of a custom post type. (5 posts)

  1. Frumph
    Member
    Posted 1 year ago #

    For Advanced Forum:

    So, basically I have a custom post type that has several taxonomies associated with it.

    Comic (Post Type)
    - Chapter (taxonomy)
    - Characters (taxonomy)

    What i'm trying to get is get the characters (terms) that are inside of a specific chapter (taxonomy ID)

    I've been following this thread from 3 years ago http://wordpress.org/support/topic/get-tags-specific-to-category?replies=38 and it doesn't seem to want to return anything for me, maybe if someone could tell me where I went wrong?

    $chapter = 3; // ID # of chapters taxonomy
    	$sql_string3 = "SELECT DISTINCT terms2.name as tag
    			FROM
    			wp_posts as p1
    			LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
    			LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
    			LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,
    
    			wp_posts as p2
    			LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
    			LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
    			LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
    			WHERE
    			t1.taxonomy = 'chapters' AND p1.post_status = 'publish' AND terms1.term_id = ".$chapter." AND
    			t2.taxonomy = 'characters' AND p2.post_status = 'publish'
    			AND p1.ID = p2.ID";
  2. vtxyzzy
    Member
    Posted 1 year ago #

    The query seems to work for me.

  3. Frumph
    Member
    Posted 1 year ago #

    Soo basically it's finding all of the characters in the chapter for you? .. yow.. okay. It's not for me; what is your taxonomies setup like? are they set to a post or a custom post-type? ...

  4. vtxyzzy
    Member
    Posted 1 year ago #

    Custom Post type.

    Parks (Custom Post type)
    -parktype (taxonomy)
    -pricerange (taxonomy)

    My 'parktype' terms are like 'waterpark', 'amusementpark', 'naturepark', etc.

    My 'pricerange' terms are like 'economy', 'moderate', 'luxury', etc.

    92 is the term_taxonomy_id for 'waterpark' and I get back 'economy' and 'moderate' because I have no waterparks in the luxury price range.

  5. Frumph
    Member
    Posted 1 year ago #

    HAH! Wouldn't you know it's as something as simple as the the return being written as $chracter_list =
    .. missing an a in my code. damnit! Thanks vtxyzzy you saying it worked gave me the pointer that it wasn't the sql so it had to be the assignments !

    Appreciate it

Topic Closed

This topic has been closed to new replies.

About this Topic