The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Custom Taxonomies
Custom post type and custom taxonomies (2 posts)

  1. kenjox
    Posted 2 years ago #

    Hi guys.
    Am a newbie to wordpress and I would like to display custom post type which is has two custom taxonomies. I would like to group those posts in relation to those two taxonomies it belongs to. From the codex I came across "tax_query" and i have come up with something like this

    $args = array(
    			'post_type' => 'ved',
    			'tax_query' => array(
    				'relation' => 'AND',
    					'taxonomy' => 'ved_brand',
    					'field' => 'slug',
    					'terms' => array('stuv','hwam','metalfire')
    					'taxonomy' => 'ved_type',
    					'field' => 'slug',
    					'terms' => array('braskaminer','spisinsatser','oppna-spisar')
    		$query =  new WP_Query($args);

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    So how can I sought those custom posts using the code I have. My goal is to group them as shown in this image https://dl.dropboxusercontent.com/u/21316108/Screen%20Shot%202013-09-09%20at%206.51.43%20PM.png I will really appreciate if anyone can help me out


  2. bcworkz
    Posted 2 years ago #

    Your query simply returns all posts of type 'ved' where there is at least one matching term in each taxonomy. In order to group and order your posts, there are arguments for most post table columns and metadata, but not taxonomies. I was unable to view your group image, so I'm not sure what you have in mind. Anyway, If your desire does not match one of the available arguments, one approach to arrange the results is to modify the actual query string by using WP_Query Filters.

    Another would be to use WP_Query to get the matching posts and then arrange the results with PHP using one of the numerous array sort functions.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Taxonomies
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic