Support » Fixing WordPress » Make posts appear ASC but with custom coding.

  • Hello guys, i’m in need of your precious help!

    I have many categories that shows posts.
    The query code is modified so that the category will only show posts that belong in the currently viewed category and NOT in its child subcategories.

    So far, the code works well.

    My question is, what do i have to add in order to show posts ascendingly? This is the code:

    $subcategories = get_categories(array('type' => 'post', 'child_of' => $_GET['cat']));
    foreach ($subcategories as $i => $value) {
        $excluded_cats .= ",-".$value->cat_ID;
    if (!empty($excluded_cats)) {
       $MainLoopArgs = array('cat' => $_GET['cat'] . $excluded_cats);
    else {
       $MainLoopArgs = array('cat' => $_GET['cat']);
    query_posts( $MainLoopArgs );
    while ( have_posts() ) : the_post(); ?>

    I thought by adding a:

    query_posts( $MainLoopArgs . '&order=ASC' );

    would work.. but it doesn’t.

    Anyone can help me?

    Thanks in advance 🙂

    [No bumping. If it’s that urgent, consider hiring someone.]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Add the order into your $MainLoopArgs like this:

    $MainLoopArgs = array('cat' => $_GET['cat'], 'order' => 'ASC');

    That should show the posts in ‘oldest first’ order.

    You mean something like that:

    $MainLoopArgs = array('cat' => $_GET['cat'], 'order' => 'ASC' . $excluded_cats);

    It didn’t work. I think the excluded categories didn’t work and the order did. The important thing is that the posts after being filtered to show up or not, should be order ASC. Now it shows all recent posts in ASC without filtering if they exist in an excluded category.

    You have anything in mind?

    Not quite. Try this:

    $MainLoopArgs = array('cat' => $_GET['cat'] . $excluded_cats, 'order' => 'ASC');

    Great that worked perfectly!

    I thank u very much. I have tried every single way to do this, but the $excluded_cats was always last..

    You’re the man, thanks again mate!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Make posts appear ASC but with custom coding.’ is closed to new replies.