Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to figure out how to do the following type of query: I want to return up to 12 posts (0 thru 11) by page/menu_order. If there are more than 12 posts, but only 5 pages have an order assigned only return those 5 pages.

Initially, I thought I'd start by using WP Query and try to do something with offset, but it's a bit beyond my comprehension.

function wu_t3_topnav() {
global $post;

// WP_Query arguments
$args = array (
    'post_parent'       => 0,
    'post_type'                 => 'page',
    'post_status'              => 'publish',
    'posts_per_page'       =>  '12',
    'order'                     => 'ASC',
    'orderby'                   => 'menu_order',
);

// The Query
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();

        $menutitle = get_post_meta( $post->ID,     '_cmb_wu_menutitle', true );

        ?>
        <li><a href="<?php echo get_permalink(); ?>">
            <?php
            if ($menutitle != '') {
                echo "$menutitle";
            } elseif ($menutitle = '') {
                // echo "Blank";
            } else { ?>
                <?php echo get_the_title(); ?>
            <?php }
            ?>
        </a></li>

    <?php }

} else {
    // Do Something
}

// Restore original Post Data
wp_reset_postdata();

}
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.