0

I have a scenario where i want to get featured property first then other properties which are not featured. I have saved a meta_key with _property_featured with 1 if the property is featured. For this i'm using pre_get_posts hook, here is the code

      function my_property_modify_query( $query ) {
         if ( is_post_type_archive('property') || is_tax('property_contracts')) {
             set_query_var( 'orderby', 'meta_value_num' );
             set_query_var( 'meta_key', '_property_featured' );
             set_query_var( 'ORDER', 'DESC' );
         }
      }
      add_action( "pre_get_posts", "my_property_modify_query" ); 

but it only shows featured property any suggestion why is he doing this ?

Touqeer Shafi
  • 5,084
  • 3
  • 28
  • 45

1 Answers1

0

Please try to put the meta_key before the orderby parameter. And I think you don't need to use meta_value_num since 1 is just a flag and the the ordering will give you some strange results.

Federico Vezzoli
  • 696
  • 1
  • 5
  • 9
  • I have fixed it, basically in the wp_postmeta when my post is saving if featured checkbox is checked it save _property_featured by 1 otherwise it removed _property_featured meta_key so thats why its showing only the featured property. Now i have saved _property_featured by 0 also and it works ! – Touqeer Shafi Aug 29 '14 at 07:46
  • Okay good, so it was showing only them because the other posts didn't have the meta. – Federico Vezzoli Aug 29 '14 at 08:22