Skip to content

Instantly share code, notes, and snippets.

@digisavvy
Last active December 18, 2015 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digisavvy/5807775 to your computer and use it in GitHub Desktop.
Save digisavvy/5807775 to your computer and use it in GitHub Desktop.
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