Skip to content

Instantly share code, notes, and snippets.

@digisavvy digisavvy/gist:5807775

Last active Dec 18, 2015
Embed
What would you like to do?
Just a simple query put together using WP_Query. I used this on a site to list out course materials (custom post type) to the currently logged-in user. The user will only see courses that they have the capability to see. This is used in Conjunction with Jigoshop and the Groups/Subscriptions plugin from Itthinx.
<?php
$args = array(
'post_type' => 'courses',
'perm' => 'readable',
'order' => 'DESC',
'orderby' => 'title',
'posts_per_page' => -1
);
$course_posts = new WP_Query($args);
if($course_posts->have_posts()) :
while($course_posts->have_posts()) :
$course_posts->the_post();
?>
<ul class="display-posts-listing">
<li class="listing-item"><a href="<?php echo get_permalink( ); ?>" title="<?php the_title() ?>"><?php the_title() ?></a></li>
</ul>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
// Reset Post Data
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.