Tagged: ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #922125

    Hi there,

    I created a page with a menu in the left side bar where you can choose post by catogory (Selecteer op soort:), by tag (Selecteer op doelgroep:), or you can look up all the post in alphabetical order (Van A tot en met Z:). This last one is the actual post page on the website.

    I used some custum code from the WordPress Codex in my childtheme functions.php to alphabetize the post:

    function foo_modify_query_order( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'orderby', 'title' );
            $query->set( 'order', 'ASC' );
        }
    }
    add_action( 'pre_get_posts', 'foo_modify_query_order' );

    This works great for the actual post page (Van A tot en met Z:). But when you look at the post by catagory or tag they appear in random order. What i want is that all my post always appear in alphabetical order. How can i manage this?

    I am pretty new with WordPress and custom coding. So maby there is a simple solution, but i don’t see it. Hope you can help.

    Thanks

    #922141

    Hey hanssmeijsters,

    Please try the function below, in the above function you limited code to apply only to the home page and the main query, the one below will work on category and tag pages

    
    function foo_modify_query_order( $query ) {
        if ( ($query->is_home() && $query->is_main_query()) || is_archive() || is_tag() ) {
            $query->set( 'orderby', 'title' );
            $query->set( 'order', 'ASC' );
        }
    }
    

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #922170

    Hi Victoria,

    Thanks a lot for your quick response. Works great! Problem solved.

    Best regards,
    Hans

    #922258

    Hi Hans,

    Glad you got it working for you! :)

    If you need further assistance please let us know.

    Best regards,
    Victoria

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.