Viewing 1 replies (of 1 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi @prozaco

    With this in your (child) theme’s functions.php the posts will be sorted alphabetically.

    add_filter( 'related_posts_by_taxonomy', 'km_rpbt_orderby_title', 10, 4 );
    function km_rpbt_orderby_title( $results, $post_id, $taxonomies, $args ) {
    
    	usort( $results, 'km_rpbt_sort_by_title' );
    	return $results;
    }
    
    function km_rpbt_sort_by_title( $a, $b ) {
    
    	return strcasecmp( $a->post_title, $b->post_title );
    }

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

Viewing 1 replies (of 1 total)
  • The topic ‘Sort posts alphabetically’ is closed to new replies.