I’m working with WordPress 3.1.4 – and trying to dynamically populate a menu with Custom Posts with a specific category as you can see here.
So on the page – I have the main loop – which is listing through all of the toy products. The products are all from a custom post type labelled ‘products’ – and each product belongs to a different category – soft toys, games etc.
In the sidebar menu, i have written the following code for each category in order to list products within the given category:
<ul class="acitem">
<?php query_posts(array ('post_type' => 'products''cat=games')); ?>
<?php $games_query = new WP_Query("category_name=games"); ?>
<?php while ($games_query->have_posts()) : $games_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
For some reason no list items are being generated. Is it possible this is a conflict with the main loop on the page?
Any suggestions or pointers appreciated! –
PS – I’m using the following plugins:
- custom post type ui
- WP page-navi
in case this has any bearing.
Please try the following code snippet.
http://codex.wordpress.org/Class_Reference/WP_Query
I eventually got this to work by swapping the second line of boxofts’ code for the following –