Pergunta

I have the following ALMOST working perfectly, but have run into a couple of issues.

Right now this displays a Books archive page, ordered like this:

Genre Name

-- Series Name

--- Books within series, sorted by book-in-series (aka reading order)

Which is fantastic - I can't tell you how long it's taken me to get to this point! :) But, I would also like to be able to determine sort order for the Series within each Genre. Is this possible? Right now it does not seem they are ordering by anything I can control; it's not by published-on date or alphabetically for instance.

[SIDEBAR: I also have a question on how to display books which have not been assigned a "book in series" meta-key (they will be within a series called "Stand Alone Titles" but it doesn't make sense for the admins to have to give them book-in-series numbers). I first asked that question here but it might make more sense within the context of my full code, so I wanted to cross-reference it.]

Here's my code:

// QUERY THAT PULLS ALL SERIES SORTED BY GENRE
$args = array( 
    'post_type' => 'series', 
    'posts_per_page' => -1,
    'nopaging' => true,
    'surpress_filters' => true,
    'orderby' => 'meta_value',
    'order' => 'DESC',
    'meta_key' => 'genres',
); 

$series = new WP_Query( $args);

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

    <?php
        // ESTABLISH PREVIOUS GENRE AS SOMETHING IMPOSSIBLE (NOT BLANK)
        $previous_genre = 'dfasd33';

        while( $series->have_posts() ) : $series->the_post();
            // Get custom post data to set current genre
            $current_genre =  get_post_meta( get_the_ID(), 'genres', true );
            if( $current_genre != $previous_genre ) {
                echo '<h2>' . stripslashes($current_genre) . '</h2>';
            }
            $previous_genre = $current_genre; 
        ?>
            <!-- DISPLAY THE SERIES NAME AND DESCRIPTION -->
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <?php the_content(); ?>

            <?php

                $current_series_id = $series->post->ID;

                // QUERY THAT PULLS ALL BOOKS WITH PARENT ID OF CURRENT SERIES SORTED BY BOOK-IN-SERIES
                $args = array( 
                    'post_type' => 'books', 
                    'posts_per_page' => -1,
                    'nopaging' => true,
                    'surpress_filters' => true,
                    'orderby' => 'meta_value',
                    'meta_key' => 'book_in_series',
                    'order' => 'ASC',
                    'post_parent' => $current_series_id,
                );

                $books = new WP_Query( $args);

                    if( $books->have_posts() ) : 

                    while( $books->have_posts() ) : $books->the_post(); ?>
                        <h4><?php the_title(); ?></h4>

                    <?php endwhile; //end book query while statement ?>
                    <?php endif; // end book query if statement ?>

            <?php endwhile; // end series query while statement ?>

<?php endif; // end series query if statement ?>

Thanks for your help!

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a wordpress.stackexchange
scroll top