Answers for "wordpress show only sticky posts"

0

wordpress show only sticky posts

$sticky = get_option( 'sticky_posts' );
$args = array(
        'posts_per_page' => 1,
        'post__in' => $sticky,
        'ignore_sticky_posts' => 1
);
$query = new WP_Query( $args );
if ( isset( $sticky[0] ) ) {
    // insert here your stuff...
}
Posted by: Guest on May-21-2021
0

wordpress query only sticky posts

// get sticky posts from DB
$sticky = get_option('sticky_posts');
// check if there are any
if (!empty($sticky)) {
    // optional: sort the newest IDs first
    rsort($sticky);
    // override the query
    $args = array(
        'post__in' => $sticky
    );
    query_posts($args);
    // the loop
    while (have_posts()) {
         the_post();
         // your code
    }
}
Posted by: Guest on September-10-2020

Code answers related to "wordpress show only sticky posts"

Browse Popular Code Answers by Language