Support

Account

Home Forums Add-ons Flexible Content Field Order of Flexible Content Field

Unread

Order of Flexible Content Field

  • Hi there,

    on the page http://dev.kinnertied.npire.de/projekte/ I use a flexible content field, which orders the project wrongly. I know I can order the flexible content in backend, but then the enduser for whom I’m making the site would always have to order it by herself as she would make a new project.

    This is my code:

    <?php
    /* Template Name: Projekte */
    get_header();
    ?>
    
    <?php $the_query = new WP_Query('post_type=projekte&orderby=projekt&order=DESC'); ?>
    <div id="content" class="clearfix" role="main">
        <?php if (have_posts()): while (have_posts()) : the_post(); ?>
                <div id="title"><h1><?php the_title(); ?></h1></div>
                <p><?php the_content(); ?></p>
                <?php
                if (have_rows('projekt')):
                    while (have_rows('projekt')) : the_row();
                        if (get_row_layout() == 'jahr'):
                            ?>
    
                            <div class="jahreszahl">&nbsp;<?php the_sub_field('jahreszahl'); ?>&nbsp;</div>
    
                        <?php elseif (get_row_layout() == 'projektreihe'):
                            ?>
    
                            <div class="projektreihe">
                                <div class="projektbild"><?php echo wp_get_attachment_image(get_sub_field('projektbild')); ?></div>
                                <div class="monat"><?php the_sub_field('monat'); ?></div>
                                <div class="headline"><?php the_sub_field('headline'); ?></div>
                                <div class="subline"><?php the_sub_field('subline'); ?></div>
                                <?php
                                if (have_rows('links')):
                                    while (have_rows('links')) : the_row();
                                        if (get_sub_field('linkbezeichner'))
                                        {
                                            ?> 
                                            <a class="url" href="<?php the_sub_field('url'); ?>"><?php the_sub_field('linkbezeichner'); ?></a>
                                            <?php
                                        }
                                        else
                                        {
                                            ?>
                                            <a class="url" href="<?php the_sub_field('url'); ?>"><?php the_sub_field('url'); ?></a>
                                            <?php
                                        }
                                    endwhile;
                                endif;
                                ?>
                            </div>
                            <?php
                        endif;
    
                    endwhile;
    
                else :
    
                // no layouts found
    
                endif;
                ?>
                <?php
            endwhile;
        endif;
        ?>
    </div><!-- #content -->
    
    <?php
    get_footer();
    

    I tried already
    <?php $the_query = new WP_Query('post_type=projekte&orderby=projekte&order=DESC'); ?>
    with orderby=projekte and orderby=jahreszahl, each with order=ASC and order=DESC.

    None of it helped. What can I do to order the whole by ‘jahreszahl’?

    EDIT: I found a big mistake I made: If I never run $the_query against the loop nothing can change. I updated my code a bit:

    <?php $the_query = new WP_Query('page_id=37&orderby=projekt&order=DESC'); ?>
    <div id="content" class="clearfix" role="main">
        <?php if ($the_query->have_posts()): while ($the_query->have_posts()) : $the_query->the_post(); ?>

    But it didn’t help. No matte if I take order=ASC or order=DESC.

    Perhaps I should run a query against have_rows, but I don’t know how to do that.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.