Forum Replies Created

Viewing 1 replies (of 1 total)
  • function wpb_latest_sticky() {

    /* Get all sticky posts */
    $sticky = get_option( ‘sticky_posts’ );

    /* Sort the stickies with the newest ones at the top */
    rsort( $sticky );

    /* Get the 3 newest stickies (change 3 for a different number) */
    $sticky = array_slice( $sticky, 0, 3 );

    /* Query sticky posts */
    $the_query = new WP_Query( array( ‘post__in’ => $sticky, ‘ignore_sticky_posts’ => 1 ) );
    // The Loop
    if ( $the_query->have_posts() ) {
    $return .= ‘

      ‘;
      while ( $the_query->have_posts() ) {
      $the_query->the_post();
      $return .= ‘

    • ‘ . get_the_title() . ‘<br />’ . get_the_excerpt(). ‘
    • ‘;

      }
      $return .= ‘

    ‘;

    } else {
    // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    return $return;

    }
    add_shortcode(‘latest_stickies’, ‘wpb_latest_sticky’);

Viewing 1 replies (of 1 total)