最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - How to display multiple custom fields with the same meta_key in an ascending order?

programmeradmin1浏览0评论

I am using query_posts to display a list of custom fields from some posts on my WordPress site. Each post has at least one custom field called showcase. In some cases, there are two showcase entries.

I have been able to display more than one showcase from the array, but when ordering the results of the two showcases they are arranged next to each other rather than in order with all the results.

For example. The results come back as - .at/on, 8Bitch, Nightwave, 8cylinder, A Souvenir, A Thousand Details, A Vengeance, ...

The 8Bitch post has two entries in the showcase custom field, one is 8Bitch and the other is Nightwave, but I have been unable to work out how to get Nightwave displayed in order in respect to all of the results.

This is the code I am using at the moment.

        <?php $args = array(
        'category_name' => 'broadcasts',
        'posts_per_page' => -1,
        'meta_key' => 'showcase',
        'orderby' => 'meta_value',
        'order' => 'ASC',
        'tag__not_in' => array('2498','123',)
    );
    query_posts($args);
    while (have_posts()) : the_post(); ?>
        <?php $featured_artist = get_post_meta( $post->ID, 'showcase', false );
        // Let's check if there's any
        if( ! empty( $featured_artist ) ) { ?>
            <span class='featartist'> 
            <?php // Check if an array -> has more than one
            if( is_array( $featured_artist ) ) {
            // Loop through each twitter url
                foreach( $featured_artist as $single_featartist ) { ?>
                    <a href="<?php the_permalink(); ?>"><?php echo $single_featartist; ?></a>, <?php }
                }   
                else { ?>
                <?php } ?>
            </span>
        <?php } ?>
        <?php endwhile; ?>

My research led me to believe it can be done with meta_query but I have been unable to work out the correct order for it.

'meta_query' => array(

Any help greatly appreciated. Thankyou.

发布评论

评论列表(0)

  1. 暂无评论