Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

frogy6 on "Custom Postype - Category archive"

$
0
0

Guys...

I use magic fields 2 and able to create a set of category for each custom post type.
also manage to get archive of category from 1st custom post type (workout).

When try on 2nd and 3rd custom post type i cant figure out how.

Here is what i have in functions.php


add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else $post_type = array('post','workout'); // replace cpt to your custom post type
$query->set('post_type',$post_type);
return $query;
}
}

and here is the category list


<?php $customPostTaxonomies = get_object_taxonomies('workout');
if(count($customPostTaxonomies) > 0)
{foreach($customPostTaxonomies as $tax)
{$args = array(
'orderby' => 'name',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'taxonomy' => $tax,
'title_li' => ''
); ?>

<ul id ="subnav">
<?php wp_list_categories( $args ); ?>

<?php}
}
?>

Thanks...


Viewing all articles
Browse latest Browse all 8245

Trending Articles