Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Do not show sticky posts new WP_Query

Discussion in 'Misc WordPress Requests' started by lizverd, Oct 28, 2017.

  1. lizverd

    Guest

    Do not show sticky posts new WP_Query, by lizverd

    Standard code, correctly prints posts, but does not want to output sticky_posts and class=”sticky” from post_class();

    <?php
    $cat_id = ts_get_option('settings_theme_cat_id');
    $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    $default_posts_per_page = get_option( 'posts_per_page' );

    $my_posts = new WP_Query(
    array(
    'cat' => $cat_id,
    'paged' => $paged,
    'post_type' => 'post',
    'post_status' => 'publish',
    'ignore_sticky_posts' => 1,
    'posts_per_page' => $default_posts_per_page,
    )
    );
    ?>
    <?php if ($my_posts->have_posts()) : while ($my_posts->have_posts()) : $my_posts->the_post(); ?>
    <?php post_class(); ?>
    <?php endwhile; endif; ?>

    Does not print here because of him $my_posts->
    If you remove it, the sticky posts and the class will be displayed
    How correctly to deduce the sticky posts with my code?

    Do not show sticky posts new WP_Query
     
    #1

Share This Page

Web Hosting