Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:15:01+00:00 2026-06-12T13:15:01+00:00

I am running a custom query but when returning posts_per_page, it is always two

  • 0

I am running a custom query but when returning posts_per_page, it is always two behind. I am using a custom post type called events, that is pulling in the code to display the posts from the functions file. I also want to implement pagination(not working also), will this be a problem?

I have ran var dump which returns everything in the query including posts before the current date. I imagine because it’s dumping before the if statement? Any ideas?

Any ideas?

<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    //Current exhibitions
    $args = array(
           'post_type' => 'exhibitions',
           'orderby'   => 'exhibition_start_date',
           'meta_key'  => 'exhibition_start_date',
           'order'     => 'ASC',
           'posts_per_page' => 6,
           'paged' => $paged
       );

        $my_query = new WP_Query( $args );

      while ( $my_query->have_posts() ) : $my_query->the_post();
           $exhibition_start_date = get_post_meta($post->ID, 'exhibition_start_date', true);
           //Current

           if ($exhibition_start_date >= date('Y-m-d') ) {
               get_exhibition_container();
           }

        endwhile;

   wp_reset_postdata();
?>

New code: (I’ve also added in my initial loop which brings in the page content, thought it could interfear?)

<div role="main" class="clearfix">  
    <div class="one-column">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endwhile; else: ?>
     <?php endif; ?>

<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    //Current exhibitions
    $args = array(
           'post_type' => 'exhibitions',
           'meta_query' => array(
           array (
                    'key' => 'exhibition_start_date',
                    'value' => date('Y-m-d'),
                    'compare' => '>='
                 )
            ),
           'orderby'   => 'exhibition_start_date',
           'meta_key'  => 'exhibition_start_date',
           'order'     => 'ASC',
           'posts_per_page' => 10,
           'paged' => $paged
       );

        $my_query = new WP_Query( $args );


      while ( $my_query->have_posts() ) : $my_query->the_post();
           $exhibition_start_date = get_post_meta($post->ID, 'exhibition_start_date', true);
           //Current
            get_exhibition_container();


        endwhile;

   wp_reset_postdata();
?>

<div class="previous-holder">
<?php previous_posts_link(); ?>
</div>
<div class="next-holder">
<?php next_posts_link(); ?>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:15:02+00:00Added an answer on June 12, 2026 at 1:15 pm

    Instead of using a if condition in your loop, you should use meta_query param :

    $args = array(
        'post_type' => 'exhibitions',
    
        'meta_query' => array(
            array(
                'key' => 'exhibition_start_date',
                'value' => date('Y-m-d'),
                'compare' => '>='
            )
        ),
    
        'orderby'   => 'exhibition_start_date',
        'meta_key'  => 'exhibition_start_date',
        'order'     => 'ASC',
    
        'posts_per_page' => 6,
        'paged' => $paged
    );
    

    EDIT : About pagination

    previous_posts_link codex :

    Prints a link to the previous set of posts within the current query.

    You should try using previous_posts_link() and next_posts_link() before wp_reset_postdata()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a global post query running, but for some reason my custom meta
I have created a custom post type for my portfolio page. I have two
I enjoy running custom scripts on pages that I do not own or control.
I have a client that is running a custom VB 6 application they wrote
I managed to get custom themes running for Tabs but still got a lil
I'm taking over a website for a client that is running on a custom
I'm running a WordPress website with a custom template that is showing me a
I'm trying to query a running state machine workflow using StateMachineWrokflowInstance in ASP.NET MVC.
How can I return a table from an UDF that executes a custom query
I am running a query against a providex database that we use in MAS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.