This topic has 12 replies, 2 voices, and was last updated 8 years by allspy.

  • Author
  • #101132
     allspy
    Participant

    Related Articles that appear after a post are not presented by order date.

    I really need to present related posts ordered by date. Any idea how to fix it?

    #101156
     sharmstr
    Moderator

    See if this works…

    Copy /kleo/page-parts/posts-related.php to your child theme (/kleo-child/page-parts/posts-related.php) and add the orderby date parameter to the argument list like…

    replace

    COPY CODE
    
    $args['tax_query'][] = array(
                    'taxonomy' => $tax,
                    'field' => 'id',
                    'terms' => $terms
                );
    

    with this

    COPY CODE
    
    $args['tax_query'][] = array(
                    'taxonomy' => $tax,
                    'field' => 'id',
                    'terms' => $terms,
                    'orderby' => 'date'
                );
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #101159
     sharmstr
    Moderator

    Moving this because its not a bug.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #101182
     allspy
    Participant

    Hi,

    This error is now visible where the related posts where present:

    Parse error: syntax error, unexpected ”orderby” (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in /home/sitedemo/public_html/wp-content/themes/kleo-child/page-parts/posts-related.php on line 44

    Thanks

    #101183
     sharmstr
    Moderator

    Looks like you either forgot the comma after $terms or when you copied the code, the quote marks got screwed up.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #101197
     allspy
    Participant

    Hi,

    The code is exactly has you show.

    The original on my file:

    COPY CODE
        if (!empty($categories)) {
            foreach( $categories as $tax ) {
                $terms = wp_get_object_terms($post->ID, $tax, array('fields' => 'ids'));
    
                $args['tax_query'][] = array(
                    'taxonomy' => $tax,
                    'field' => 'id',
                    'terms' => $terms
                );
            }
        }
    }

    How it satys after the update:

    COPY CODE
        if (!empty($categories)) {
            foreach( $categories as $tax ) {
                $terms = wp_get_object_terms($post->ID, $tax, array('fields' => 'ids'));
    
                $args['tax_query'][] = array(
                    'taxonomy' => $tax,
                    'field' => 'id',
                    'terms' => $terms,
                    'orderby' => 'date'
                );
            }
        }
    }

    Do you see anything wrong?

    Thanks

    #101209
     sharmstr
    Moderator

    No I dont. I copied into my file and it works perfectly. No errors. If you want to give me access I’ll have a look.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #102273
     allspy
    Participant
    This reply has been set as private.
    #102290
     sharmstr
    Moderator

    Not sure why you were getting the error, I added the code and there were no errors.

    In any case, I gave you the wrong code. Its fixed now and your related articles are in date order. You will lose that change during the next Kleo update since you’re not running the Kleo child theme. After you update, be sure to change ‘rand’ to ‘date’ at the top of the file.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #102296
     allspy
    Participant
    This reply has been set as private.
    #102298
     sharmstr
    Moderator

    The code already limits to the same category. If the file is in your child theme, change ‘rand’ to ‘date’ at the top of the file as I’ve instructed.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #104083
     allspy
    Participant

    Hi,

    Can you please confirm if you added the code to my child the,e or to the main theme?

    Thanks

    #104084
     allspy
    Participant

    Hi,

    Thank you, I found the code on the child-theme and chamge ‘rand’ to ‘date’.

    It’s working now.

    Thanks for your help.

    Regards

Viewing 13 posts - 1 through 13 (of 13 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?