B
B
Boris Belov2015-10-28 16:42:25
PHP
Boris Belov, 2015-10-28 16:42:25

How to exclude the current entry from the given code?

Good day
There is a code - the output of popular articles, how to hide the current record on which we are?

function sky_popular_posts($num) {
    global $wpdb;

    $querystr = "SELECT $wpdb->posts.post_title, $wpdb->posts.comment_count, $wpdb->posts.ID FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ORDER BY $wpdb->posts.comment_count DESC LIMIT $num";
    $popposts = $wpdb->get_results($querystr, OBJECT);
    if (count($popposts)>0) {
        $count = 0;
        foreach ($popposts as $post) {
          
            $count++;
            $class = 'item';
            if ($count==$num) $class = 'last';
            ?>
                        <li>
<a class="thumbpopular" href="<?php echo get_permalink($post->ID); ?>" title="<?php the_title(); ?>" ><?php echo get_the_post_thumbnail($post->ID, array('sidebar70')); ?></a>
<a href="<?php echo get_permalink($post->ID); ?>" title="<?php the_title(); ?>"><?php echo $post->post_title; ?></a>
</li>

            <?php
        }
    }
}


I assumed to use exclude or posts_not-in but neither works.
Need help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Belov, 2015-10-28
@iborisbelov

<?php
$mainId=$post->ID;
$args = array( 'showposts' => 5, 'meta_key' => 'post_views', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'post__not_in' => array($post-> ID), );
query_posts($args);
while ( have_posts() ) : the_post();
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question