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

categories - Modifying category order

programmeradmin3浏览0评论

I am working with a directory style wordpress theme that displays categories in masonry style columns with their posts listed under each category title. The categories are appearing on the front page in alphabetical order and I would like to change this preferably using advanced custom fields. I have managed to control the post order using acf just fine but am stumped as to how to change category order.

<?php
                    $home_cats = get_post_meta($post->ID, 'home_cats', true);
                    $select_categories = explode( ',', $home_cats );
                    foreach ( $select_categories as $cat ) {
                        $tax_query = array(
                            array(
                                'taxonomy' => 'category',
                                'field'    => 'id',
                                'terms'    => $cat,
                            ),
                        );
                        $term = get_term( $cat, 'category' );
                        $term_name = $term->name;
                        $args = array(
                            'posts_per_page'    => -1,
                            'post_type'         => 'post',
                            'tax_query'         => $tax_query,
                            'meta_key'       => 'placement',
                            'orderby'        => 'meta_value_num',
                            'order'          => 'ASC',
                        );
                        $the_query = new WP_Query( $args );
                        if( $the_query->have_posts() ) :
                        ?>

I assumed adding orderby and order fields to first tax_query array was the way to achieve this but it doesn't change a thing. Is it glaringly obvious to one of you experts where I am going wrong here? Thanks

发布评论

评论列表(0)

  1. 暂无评论