WordPress get by and exclude by meta data messes pagination

So this is my first post and wow, I didn’t know this site existed. I’ve had a look around at questions and I hope that mine isnt a dumb nooby one. Although I am a noob :S

Ok, so I created a function in WordPress that will add a meta box to the new posts page so that I can specify whether or not this post should be featured (I read this is better than creating a featured category for SEO purposes?).

Anyway.. The code I have works in showing the most recent. Here is the code for that:

  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
  while ($my_query->have_posts()) : $my_query->the_post();
  $custom = get_post_meta($my_query->post->ID, '_featuredpost_meta_value_key', true);
if (  $custom ){
<article class="container" itemprop="blogPosts" itemscope itemtype="http://schema.org/BlogPosting">
    <div class="row">
        <h2 itemprop="about">
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <div class="row">
        <div class="<?php if ( has_post_thumbnail() ) { ?>two-thirds column<?php } else {?> twelve columns  <?php } ?>">
            <p class="post-excerpt"><?php  modified_excerpt(); ?></p>
    <?php if ( has_post_thumbnail() ) { ?>
        <div class="one-third column">
            <?php the_post_thumbnail('full', array('class'=>'hide-mobile')); ?> 
    <?php } ?>      
    <div class="row">
        <a href="<?php the_permalink(); ?>" class="button button-primary">Continue Reading</a>
    <hr />
    <div class="post-info">
            <li class="date"><?php the_date();?></li>
            <li class="author"><a href="<?php bloginfo('url'); ?>/questions/user/<?php echo get_the_author_meta('user_login'); ?>"><?php echo get_the_author_meta('display_name'); ?></a></li>
            <li class="category"><?php the_category(', '); ?></li>
            <li class="tags"><?php the_tags('',', ',''); ?></li>
wp_reset_query();  // Restore global post data stomped by the_post().

Now, When I use the same code below, but then use:

 if ( ! $custom ){

to show the posts that are not set to be featured that also works. The problem is that the pagination no longer works. When I go to the second page it just duplicates what is on the home page.

This leads me to believe that I have created a mashed together crappy bit of code. Can someone please help me build a loop, that will exclude any posts where the meta data _featuredpost_meta_value_key is set to Yes.

Thanks in advance

Read more here: WordPress get by and exclude by meta data messes pagination

Leave a Reply

Your email address will not be published. Required fields are marked *