• get_the_category fetches categories from term_taxonomy where taxonomy value is ‘category’. But I want to get the categories from term_taxonomy where the taxonomy value is ‘my_custom_value’ instead of ‘category’. Can I modify get_the_category to fetch array from term_taxonomy where taxonomy is ‘my_custom_value’, or do I need to create a custom query? If a query is the only way, please advise on the best way.

    For the query…this is what I have so far. It works, but does not filter out the terms related to other posts. I can’t figure out how to tell the query, “only show me the terms where the posts.ID matches the $post->ID”. What do I need to add to this to only get terms related to the post being viewed? Thanks in advance for your help!

    $termquery= $wpdb->get_results
    ("
    SELECT $wpdb->terms.name FROM $wpdb->terms
    INNER JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
    WHERE $wpdb->term_taxonomy.taxonomy = 'my_custom_value'
    ORDER BY name ASC
    ");
    $displayterms = $wpdb->get_col($termquery['name']);
    echo json_encode($displayterms);
Viewing 1 replies (of 1 total)
  • Thread Starter wordyword

    (@wordyword)

    Update: I’m able to retrieve the category term ID numbers. Now I need to figure out how to retrieve the term names instead of the IDs. Here’s what the code result looks like:

    displayterms = [“24″,”25”];

    And here’s the code. Where do I need to change the following code so that names are retrieved instead of ID #’s?

    $termquery = get_the_category
    ("
    SELECT $wpdb->name FROM terms
    WHERE $wpdb->term_taxonomy.taxonomy = 'my_custom_value'
    ");
    
    $displayterms = $wpdb->get_col($termquery['$name']);
    echo json_encode($displayterms);
Viewing 1 replies (of 1 total)
  • The topic ‘How to get categories where term taxonomy is ‘my_custom_value’’ is closed to new replies.