Created
July 29, 2012 21:31
-
-
Save amaxwell01/3201950 to your computer and use it in GitHub Desktop.
Simple and clean wordpress custom post query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<?php | |
$wp_query = new WP_Query( array( | |
'post_type' => 'gallery', | |
'posts_per_page' => -1 | |
)); | |
if( have_posts() ) { | |
while ( $wp_query->have_posts() ) { | |
$wp_query->the_post(); | |
echo '<li>' . the_title() . '</li>'; | |
} | |
} | |
else { | |
echo '<li>No Title</li>'; | |
} | |
wp_reset_query(); | |
?> | |
</ul> |
Realized that I didn't have a unordered list element for the list item to be contained in.
"the_title()" echoes itself out. Please try "get_the_title()"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change the 'posts_per_page' from 100 to -1 to default to show all posts vs a random number