I am using a recipe plugin that uses a custom post type of ‘recipe’. I currently have multiple lists of recipes from each category on a page. I am trying to get the title of each category list to link to an archive list of those posts within each category. This is not working, and I’m not sure if I need to create a new archive template, or if I can do it within this code.
<ul class="subcats-list">
<h2 class="subcats-title"><a href="<?php echo get_category_link(39); ?>" title="No Cook"><?php echo get_cat_name(39); ?></a></h2>
<?php
$recipes = new WP_Query();
$recipes->query('showposts=5&orderby=rand&cat=39&post_type=recipe');
while ($recipes->have_posts()) : $recipes->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul><!-- subcat -->
NOTE: the title for each category list does currently link to the category archive page, but there are no posts listed. Just a black archive page.
How did you create the link with your category ’39’? Is it a custom taxonomy?
Here’s the test i just did and it works fine:
In
functions.php
i created the custom post type ‘recipe‘:Then i created a custom taxonomy element to get some categories related to this custom post type:
I nammed it ‘cate-recipe‘.
I wrote 3 news posts under ‘recipe‘ in the admin and created 2 custom categories ‘cate-1‘ and ‘cate-2‘.
Then using your code, i loaded the posts from the custom post type. It works fine but doesnt take in account the custom taxonomy parameter. So here’s how i made it in the end:
I’m using the ‘
tax_query
‘ parameter to query the posts from my custom taxonomy ‘cate-recipe‘ with the term ‘cate-1‘, that i created in the admin.And it loads just the posts that have this “special category”.
Hope this helps, let me know if it suits your needs.