0
votes

I am trying to list all the post while advanced custom field value ispremium=>yes and post issticky in my WordPress site. I have following code in my page. It is listing all the post but not checking ispremium=>yes and issticky post rather showing all the posts.

What's wrong in my code?

       <?php 
               // args
                $args = array(
                'numberposts'   => -1,
                'post_type'     => 'post',
                'meta_key'      => 'ispremium',
                'meta_value'    => 'yes'

            );



            // query
            $the_query = new WP_Query( $args and is_sticky());

        ?>
        <?php if($the_query->have_posts() ): ?>
            <ul>
                <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
                    <li>
                        <a href="<?php the_permalink(); ?>">
                        <img src="<?php the_field('event_thumbnail'); ?>" />
                        <?php the_title(); ?>
                        </a>
                    </li>
                <?php endwhile; ?>
            </ul>
        <?php endif; ?>

    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>
1
Questions asking "whats wrong with this code?" are ouff topic for this site. Please review How to ask a question. You're expected to have researched your issue and made a good attempt to write the code yourself before posting. Please read How much research effort is expected of Stack Overflow users - FluffyKitten

1 Answers

1
votes

Try this:

$args = array(
        'posts_per_page'      => -1,
        'post__in'            => get_option( 'sticky_posts' ),
        'post_type'           => 'post',
        'meta_key'            => 'ispremium',
        'meta_value'          => 'yes',
        'ignore_sticky_posts' => 1,

);  
$the_query = new WP_Query( $args );