Using the WP Types Plugin, I setup a custom post type (slug: portfolio
), which has a custom taxonomy (slug: portfolio-category
).
The custom taxonomy has three items (slugs: group1
, group2
, group3
) to organize portfolio posts.
On each single portfolio page I am displaying 3 related posts from the same taxonomy term, filtered by slug:
global $post;
$term_list = wp_get_post_terms($post->ID, 'portfolio-category', array("fields" => "names"));
$wpex_port_query = new WP_Query(
array(
'post_type' => 'portfolio',
'showposts' => '3',
'orderby' => 'rand',
'post__not_in' => array($post->ID),
'no_found_rows' => true,
'tax_query' => array(
array(
'taxonomy' => 'portfolio-category',
'field' => 'slug',
'terms' => $term_list,
)
)
)
);
This basically works, but I am wondering if there is a better way than creating a global variable $post
? What is the recommended way to handle this?