Forums

[resolved] mixed categories list (3 posts)

  1. delvico
    Member
    Posted 3 years ago #

    Hi everyone!

    I've created this categories structure in my WordPress:
    - Workout:
    + Web
    + Print
    + Multimedia
    - Clients:
    + client 1
    + client 2
    ...

    For example, I want to display in the "web" archive a list of links to the "clients" for whom I've worked in that category.

    There is a fast way to display the list. A mix of template tags and/or predefined functions? Or a have to build a custom query to the database?

    Excuse my English, I'm from Spain.

    Thanks in advance!

  2. stvwlf
    Member
    Posted 3 years ago #

    Hi

    You will have to build a custom query. WordPress categories are hierarchical only. There is no built in way to access subcategories of a different parent category.

  3. delvico
    Member
    Posted 3 years ago #

    ok, thank u.

    I've built a custom query, here it is:

    SELECT *
    	FROM wp_terms wpt
    		LEFT JOIN wp_term_taxonomy wptt ON wpt.term_id = wptt.term_id
    		LEFT JOIN wp_term_relationships wptr ON wptt.term_taxonomy_id = wptr.term_taxonomy_id
    	WHERE parent = '".$clients_cat."'
    		AND wptt.taxonomy = 'category'
    		AND wptr.object_id
    		IN (
    			SELECT object_id
    			FROM wp_term_relationships wptr
    				LEFT JOIN wp_term_taxonomy wptt ON wptr.term_taxonomy_id = wptt.term_taxonomy_id
    			WHERE wptt.term_id=".$cat."
    				AND wptt.taxonomy = 'category'
    		)
    	GROUP BY wpt.term_id

    where $client_cat is the parent category "Clients" and $cat is the actual category (one of the children of the "workout" category)

Topic Closed

This topic has been closed to new replies.

About this Topic