1 comment

  1. You probably also need:

    $query->set( 'ignore_sticky_posts', true );
    

    That will prevent sticky posts from shuffling to the top.

    Maybe:

    $query->set( 'posts_per_page', -1 );
    

    If you are getting too few posts. -1 means “all”. You can use that to change to a number other than what is set in the backend.

    A couple of notes:

    1. $query->set( 'meta_key', 'key name' ); will limit the results to
      posts with that meta_key
    2. If your meta_value for the key name isn’t really a number the
      order isn’t going to work correctly. Punctuation and letters will mess this up.
    3. is_home can be peculiar. Make sure it does what you need it
      to do.

    Beyond that, you will need to explain “not returning all the posts and not ordering them properly” in better detail.

Comments are closed.