wordpress - Show post type where category equals page title -
i'm trying list posts custom post type 'article' on several pages post category matches page title. on products page there list articles category products, reviews page there list of articles category reviews, etc.
no posts returned when use category_name, , posts returned without it.
<?php // articles have category matches page title (ie: on pagination page articles pagination category) $pagetitle = get_the_title(); $posttype = 'article'; $args= array( 'post_type' => $posttype, 'post_status' => 'publish', 'category_name' => $pagetitle ); $articles = new wp_query($args); if( $articles->have_posts() ) { while ($articles->have_posts()) : $articles->the_post(); ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="permanent link <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <p class="tags"><?php the_category()?></p> <?php endwhile; } wp_reset_query(); // restore global post data stomped the_post(). ?>
the 'category_name' parameter requires use category slug, not name. category id instead name...
$catid = get_cat_id( $pagetitle );
... use 'cat' parameter in query.
'cat' => $catid,
Comments
Post a Comment