Support

Account

Home Forums General Issues Headings when ordering by custom fields

Unread

Headings when ordering by custom fields

  • Hello, I am using the PRO version and the code you provided in your guide below:` <?php

    // get posts
    $posts = get_posts(array(
    ‘post_type’ => ‘engine’,
    ‘posts_per_page’ => -1,
    ‘meta_key’ => ‘engine_make’,
    ‘orderby’ => ‘meta_value’,
    ‘order’ => ‘ASC’
    ));

    if( $posts ): ?>

    <ul>

    <?php foreach( $posts as $post ):

    setup_postdata( $post )

    ?>
    <li>
    <a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a>
    </li>

    <?php endforeach; ?>

    </ul>

    <?php wp_reset_postdata(); ?>

    <?php endif; ?>`

    It displays all that is expected in order:

    Briggs XR2100
    Briggs & Stratton 9S500 series
    Champion 171cc

    My issue is I would like the items to be separated by each meta value by a title of that engine_make.

    In other words, I love the sorting method but need to know how to put the engine_make meta value title above each corresponding section like this:

    Briggs & Stratton
    Briggs XR2100
    Briggs & Stratton 9S500 series

    Champion
    Champion 171cc

Viewing 1 post (of 1 total)

The topic ‘Headings when ordering by custom fields’ is closed to new replies.