Custom post categories listing with loop?
-
I’m not a programmer so please excuse my ‘noviceness’.
The site I run has two custom post types. One of them is ‘portfolio-category’ (slug).
I wanted to have a page where I can show only the particular custom posts categorised by the custom taxonomy (a set of categories) for that post type. I looked everywhere but couldn’t find anything so I ‘hacked’ around and found one very silly way to make it work.<h3>Weddings</h3> <ul> <?php global $post; $args = array( 'post_type' => 'portfolio', 'portfolio-category' => 'wedding' ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li class="_archive"><a href="<?php the_permalink(); ?>" class"_archivelink"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
Basically, I repeated this snippet for each category including the heading (static). Stupid, I know but not having learned PHP from ground up I have no idea how to make this more elegant. I can only guess that I could use Loop function.. That’s as far as I went and I’m giving up after spending pretty much all day on this.
I’m sure there are experts out there who could advise me what to do?
Thank you for your kind help.
- The topic ‘Custom post categories listing with loop?’ is closed to new replies.