I'm using a wp_query on my website to display a list of child pages from a parent page. It works fine and my pages are sorted by a meta_key using a custom field. Now I would like to add a next page (when there is one) and a previous page (when there is one) on my pages using the same arguments, children page from 22, order ASC and orderby and meta_key.

Here is my wp-query :


            $args = array(
            'post_type'      => 'page',
            'posts_per_page' => -1,
            'post_parent'    => '22',
            'order'          => 'ASC',

            $parent = new WP_Query( $args );

            if ( $parent->have_posts() ) : ?>

            <span class="styled-select">

                <select name="" onchange="location = this.options[this.selectedIndex].value;">

                <option>A - Z</option>

                <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>

                        <option value="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                        <?php the_field('nom_de_loeuvre'); ?>
                        , de 
                        <?php if(get_field('prenom_artiste')): ?>
                        <?php the_field('prenom_artiste'); ?>
                        <?php endif ;?>
                        <?php the_field('nom_artiste'); ?> | Galerie 
                        <?php if(get_field('prenom_galerie')): ?>
                        <?php the_field('prenom_galerie'); ?>
                        <?php endif ;?>
                        <?php the_field('nom_galerie'); ?>


                <?php endwhile; ?>



            <?php endif; wp_reset_query(); ?>

I can't find how to do it, depending on what I tried I get the previous and next link working, but not sorted depending of my meta_key, or I get all the kinks displayed on my page...

Can anybody help me with this?

I don't want to display the next or previous page title but I'll use custom text "next" & "previous"

Thanks a lot for your help.

  • Unfortunately I don't have time to look at everything, but you should have a look at next_posts_link when using a custom query – Pieter Goosen Jun 27 '14 at 18:27
  • Have you tried setting posts_per_page to the number you want, then using the next and previous page Wordpress functions? – ssergei Jun 27 '14 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.