• Hi

    I am trying to sort posts within the subcategory in an ascending alphabetical order of their title in the sidebar..

    Something like this

    Category
    > Subcategory A
    > A Post
    > B Post

    > Subcategory B
    > A Post
    > B Post

    I am using the following code in my category template file.

    <?php
                            	foreach($categories as $category)
    							{
    								if($category->term_id == $thiscat) {   $class="current"; } else { $class = ''; }?>
    								<li >
    									<a class="<?php echo $class; ?>" href='<?php echo get_category_link($category); ?>' title="<?php echo sprintf( __( "View all documents in %s" ), $category->name ); ?>" alt="<?php echo sprintf( __( "View all documents in %s" ), $category->name ); ?>" ><?php echo $category->name; ?></a>
    									<?php
                                        	/*if($category->term_id == $thiscat)
    											{*/
    
    $arguments = array('posts_per_page' => -1,'orderby' => 'title', 'order' => 'ASC', 'category' => $category->term_id);
    			$myposts = get_posts( $arguments );
    
    							echo '<ul class= "sub-cat">';
    							foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    							<li>
    														<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    													</li>
    												<?php endforeach;
    												echo '</ul>';
    												wp_reset_postdata();
    											}
    									?>
    								</li>
                              </ul>
                          	</div>

    Can someone let me know whats wrong with this? I have tried adding a function in the functions.php and a lot of other simple stuff like removing spaces, changing the order in which $arguments are written etc.. but nothing works and I am so out of ideas.. I checked online but available problems do not match mine.

    Any help would be greatly appreciated.

    Here is the page where I am trying to display it.. check the left sidebar.

    https://www.aramanstudio.com/category/photographers/

    Thanks
    Shadab

  • The topic ‘Orderby and Order not working.. Tried everything’ is closed to new replies.