Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Vedran Vuković
Vedran Vuković
3,301 Points

Wordpress - Custom post type - Taxonomy page - order posts alphabetically

Can someone help me with this on Custom post type page everything is working fine with alphabeticall sort of posts by title:

But when I click on category it s not working fine: This is not working on taxonomy page but it s working in custom post type page where are all posts: But need in categories of custom post type to sort alphabetically

Look at this peace of code in file: taxonomy-opg_categories.php <?php $args = array( 'post_type' => 'opg', 'orderby'=>'title', 'order'=>'ASC' ); $query = new WP_Query( $args ); ?>

Look at in full code on file:

taxonomy-opg_categories.php

<?php $h = new provide_Helper(); $h->provide_header(); $opt = $h->provide_opt(); $h->provide_headerTop(get_the_ID()); $column = $h->provide_column( get_the_ID() ); $theme = $h->provide_set($opt, 'optCategoryTheme'); $blog = new provide_blog(); ?> <section> <div class="block less-space"> <div class="container"> <div class="row"> <div class="<?php echo esc_attr($column) ?>"> <div class=""> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php endwhile; endif; ?>

<?php $args = array( 'post_type' => 'opg', 'orderby'=>'title', 'order'=>'ASC' ); $query = new WP_Query( $args ); ?>

             <div class="col-md-6 col-sm-6 col-lg-6 col-xs-12">
             <div class="opg-panel">
              <a href="<?php the_permalink();?>"><?php the_post_thumbnail(''); ?></a>
             <div class="sidepost-inner">  
            <a href="<?php the_permalink();?>"><?php the_title('');?></a>

             <p style="margin-bottom: 0"><i class="fa fa-map-marker"></i>&nbsp;<?php the_field('adresa_i_mjesto');?></p>
             <p style="margin-bottom: 0"><i class="fa fa-phone"></i>&nbsp;<?php the_field('kontakt_telefon');?></p>
                <a class="opg-circle-link" href="<?php the_permalink();?>"><i class="fa fa-chevron-circle-right"></i>               

</a>

            </div>  
        </div>
        </div>


                    </div>
                </div>
                 <div class="col-md-3">
                <div class="sidebar">
                  <h4 class="widget-title">Kategorije</h4>
                <div class="widget_categories widget wow fadeInRight">
                <div class="widget-wrapper">

<ul> <?php $categories = get_categories('taxonomy=opg_categories&post_type=opg-ovi'); ?> <?php foreach ($categories as $category) : ?> <li><a href="<?php echo get_category_link($category->cat_ID); ?>"><?php echo $category->name; ?></a></li>

<?php endforeach; ?>

<ul>
</div> </div> </div> </div> </div> </div> </section> <?php

get_footer();