• Hello,

    I want to make a query to select taxonomies, but to avoid parent duplicates.
    I have this:

            $args = array(
                'orderby' => 'term_id',
                'order'   => 'DESC',
                'taxonomy' => 'episodes',
                'number' => 20
            );

    but if let’s say we have “John” and has three taxonomies named episodes and we have 1,2,3, when i select, i don’t want all of them, only the last one, is there any way?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You mean select terms with no duplicate names? Using WP_Term_Query or get_terms()? For example the taxonomy “episodes” has 3 terms all named “John”. You only want the last “John” term returned. Correct?

    Could it be only the first John term instead? It’d be a lot easier. You cannot do so directly with get_terms() either way. You’d need to modify the resulting SQL query directly through the ‘terms_clauses’ filter. Append ' GROUP BY t.name' to the $clauses['where'] element. I’ve not verified if this will work but I expect it to. GROUP BY combines matching records into one summary row on which COUNT and SUM etc. operations can work. Without such operations you essentially just get the first matching row.

Viewing 1 replies (of 1 total)
  • The topic ‘Select taxonomies from unique parent id’ is closed to new replies.