Support » Plugins and Hacks » Hacks » Custom post type and custom taxonomies

  • 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',
    				array(
    					'taxonomy' => 'ved_brand',
    					'field' => 'slug',
    					'terms' => array('stuv','hwam','metalfire')
    				),
    				array(
    					'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

    http://wordpress.org/plugins/custom-taxonomies/

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    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.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom post type and custom taxonomies’ is closed to new replies.