Last active
August 29, 2015 14:18
-
-
Save labsecrets/229bc5e3a2aa41c6ee81 to your computer and use it in GitHub Desktop.
Create And Display List Of Custom Post Types (excluding sticky posts) (see: https://1wd.tv/wordpress-sticky-posts-and-custom-wp-queries/)
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
// Code To Display Sticky Posts For All Custom Post Types | |
function lab_latest_sticky_all() { | |
$args = array( | |
'post__in' => get_option( 'sticky_posts' ), | |
'showposts' => 4, | |
'post_type' => array ('download','post', 'page', 'latest', 'topic', 'forum', 'webinars', 'hangouts', 'lessons', 'kits'), | |
'ignore_sticky_posts' => 1 | |
); | |
$the_query = new WP_Query( $args ); | |
while ($the_query -> have_posts()) : $the_query -> the_post(); ?> | |
<li><i class="fa fa-play-circle"></i><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li> | |
<?php | |
endwhile; | |
wp_reset_postdata(); | |
} | |
add_shortcode('latest_sticky_all', 'lab_latest_sticky_all'); | |
// Code To Use to Display the Sticky Post Query Shown above (use in a template file) | |
<h1>Latest QuickTips</h1> | |
<ul> | |
<?php | |
$args = array( 'numberposts' => 4 ); | |
$recent_posts = wp_get_recent_posts( $args ); | |
foreach( $recent_posts as $recent ){ | |
echo '<li><i class="fa fa-play-circle"></i><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a> </li> '; | |
} | |
?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment