Wordpress sort custom taxonomy posts by custom field value Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Wordpress query - Order by meta-field valueshow post titles below each category wordpressWordPress WP_Query: Display custom post type based on custom meta value, and also order on another custom meta valueShow posts from custom taxonomyhow woocommerce product get order by product tagWordPress taxonomy images plugin displaying all termsWordpress: Using post__not_in to exclude custom taxonomy categorySort terms on custom taxonomy by custom metadata (pre_get_terms)Get image post by taxonomy/category wordpressHow to attach custom taxonomy to a post in Wordpress?

How to translate "red flag" into Spanish?

Error: Syntax error. Missing ')' for CASE Statement

Retract an already submitted recommendation letter (written for an undergrad student)

Can I criticise the more senior developers around me for not writing clean code?

"Rubric" as meaning "signature" or "personal mark" -- is this accepted usage?

How to open locks without disable device?

How to use @AuraEnabled base class method in Lightning Component?

What to do with someone that cheated their way through university and a PhD program?

Protagonist's race is hidden - should I reveal it?

Additive group of local rings

Implementing 3DES algorithm in Java: is my code secure?

What *exactly* is electrical current, voltage, and resistance?

Passing args from the bash script to the function in the script

Trumpet valves, lengths, and pitch

Could moose/elk survive in the Amazon forest?

France's Public Holidays' Puzzle

c++ diamond problem - How to call base method only once

Seek and ye shall find

How would this chord from "Rocket Man" be analyzed?

What was Apollo 13's "Little Jolt" after MECO?

Split coins into combinations of different denominations

Would reducing the reference voltage of an ADC have any effect on accuracy?

What is /etc/mtab in Linux?

Justification for leaving new position after a short time



Wordpress sort custom taxonomy posts by custom field value



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Wordpress query - Order by meta-field valueshow post titles below each category wordpressWordPress WP_Query: Display custom post type based on custom meta value, and also order on another custom meta valueShow posts from custom taxonomyhow woocommerce product get order by product tagWordPress taxonomy images plugin displaying all termsWordpress: Using post__not_in to exclude custom taxonomy categorySort terms on custom taxonomy by custom metadata (pre_get_terms)Get image post by taxonomy/category wordpressHow to attach custom taxonomy to a post in Wordpress?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a custom taxonomy page that queries the custom post types attributed to that taxonomy, in my case the custom post type is "cars", and an example taxonomy page is "exceptional cars" or "convertibles".



On the taxonomy page "taxonomy-luxury-cars.php", I need to display the posts ordered by a custom field "display_order", but I cannot get the posts to display in the correct order.



Basically all I need is to insert an orderby "display_order" (custom field) before the "while have posts" loop, in to reorder the posts.



I have tried numerous snippets found online, but none work correctly.



Snippet 1
(only lists all posts "cars", but I need it for only the posts of the current taxonomy)



$posts = get_posts(array(
'post_type' => 'cars',
'posts_per_page' => -1,
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));


Snippet 2



 $terms = get_the_terms( get_the_ID(), 'luxury-cars' );
foreach($terms as $term)
$posts = get_posts(array(
'post_type' => 'cars',
'tax_query' => array(
array(
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
),
'numberposts' => -1
));
foreach($posts as $post)
echo get_the_title();




Snippet 3



$queried_object = get_queried_object();
$args = array(
'post_type' => 'cars',
'term' => $queried_object->slug,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => 'display_order',
'meta_query' => array(
array(
'key' => 'display_order'
)
),
'tax_query' => array(
array(
'taxonomy' => 'luxury-cars',
'terms' => array(
$queried_object->term_id
)
)
)
);
$query = new WP_Query($args);

while ( have_posts() ) : the_post();

...









share|improve this question






























    0















    I have a custom taxonomy page that queries the custom post types attributed to that taxonomy, in my case the custom post type is "cars", and an example taxonomy page is "exceptional cars" or "convertibles".



    On the taxonomy page "taxonomy-luxury-cars.php", I need to display the posts ordered by a custom field "display_order", but I cannot get the posts to display in the correct order.



    Basically all I need is to insert an orderby "display_order" (custom field) before the "while have posts" loop, in to reorder the posts.



    I have tried numerous snippets found online, but none work correctly.



    Snippet 1
    (only lists all posts "cars", but I need it for only the posts of the current taxonomy)



    $posts = get_posts(array(
    'post_type' => 'cars',
    'posts_per_page' => -1,
    'meta_key' => 'display_order',
    'orderby' => 'meta_value_num',
    'order' => 'ASC'
    ));


    Snippet 2



     $terms = get_the_terms( get_the_ID(), 'luxury-cars' );
    foreach($terms as $term)
    $posts = get_posts(array(
    'post_type' => 'cars',
    'tax_query' => array(
    array(
    'meta_key' => 'display_order',
    'orderby' => 'meta_value_num',
    'order' => 'ASC'
    )
    ),
    'numberposts' => -1
    ));
    foreach($posts as $post)
    echo get_the_title();




    Snippet 3



    $queried_object = get_queried_object();
    $args = array(
    'post_type' => 'cars',
    'term' => $queried_object->slug,
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'meta_key' => 'display_order',
    'meta_query' => array(
    array(
    'key' => 'display_order'
    )
    ),
    'tax_query' => array(
    array(
    'taxonomy' => 'luxury-cars',
    'terms' => array(
    $queried_object->term_id
    )
    )
    )
    );
    $query = new WP_Query($args);

    while ( have_posts() ) : the_post();

    ...









    share|improve this question


























      0












      0








      0








      I have a custom taxonomy page that queries the custom post types attributed to that taxonomy, in my case the custom post type is "cars", and an example taxonomy page is "exceptional cars" or "convertibles".



      On the taxonomy page "taxonomy-luxury-cars.php", I need to display the posts ordered by a custom field "display_order", but I cannot get the posts to display in the correct order.



      Basically all I need is to insert an orderby "display_order" (custom field) before the "while have posts" loop, in to reorder the posts.



      I have tried numerous snippets found online, but none work correctly.



      Snippet 1
      (only lists all posts "cars", but I need it for only the posts of the current taxonomy)



      $posts = get_posts(array(
      'post_type' => 'cars',
      'posts_per_page' => -1,
      'meta_key' => 'display_order',
      'orderby' => 'meta_value_num',
      'order' => 'ASC'
      ));


      Snippet 2



       $terms = get_the_terms( get_the_ID(), 'luxury-cars' );
      foreach($terms as $term)
      $posts = get_posts(array(
      'post_type' => 'cars',
      'tax_query' => array(
      array(
      'meta_key' => 'display_order',
      'orderby' => 'meta_value_num',
      'order' => 'ASC'
      )
      ),
      'numberposts' => -1
      ));
      foreach($posts as $post)
      echo get_the_title();




      Snippet 3



      $queried_object = get_queried_object();
      $args = array(
      'post_type' => 'cars',
      'term' => $queried_object->slug,
      'orderby' => 'meta_value_num',
      'order' => 'ASC',
      'meta_key' => 'display_order',
      'meta_query' => array(
      array(
      'key' => 'display_order'
      )
      ),
      'tax_query' => array(
      array(
      'taxonomy' => 'luxury-cars',
      'terms' => array(
      $queried_object->term_id
      )
      )
      )
      );
      $query = new WP_Query($args);

      while ( have_posts() ) : the_post();

      ...









      share|improve this question
















      I have a custom taxonomy page that queries the custom post types attributed to that taxonomy, in my case the custom post type is "cars", and an example taxonomy page is "exceptional cars" or "convertibles".



      On the taxonomy page "taxonomy-luxury-cars.php", I need to display the posts ordered by a custom field "display_order", but I cannot get the posts to display in the correct order.



      Basically all I need is to insert an orderby "display_order" (custom field) before the "while have posts" loop, in to reorder the posts.



      I have tried numerous snippets found online, but none work correctly.



      Snippet 1
      (only lists all posts "cars", but I need it for only the posts of the current taxonomy)



      $posts = get_posts(array(
      'post_type' => 'cars',
      'posts_per_page' => -1,
      'meta_key' => 'display_order',
      'orderby' => 'meta_value_num',
      'order' => 'ASC'
      ));


      Snippet 2



       $terms = get_the_terms( get_the_ID(), 'luxury-cars' );
      foreach($terms as $term)
      $posts = get_posts(array(
      'post_type' => 'cars',
      'tax_query' => array(
      array(
      'meta_key' => 'display_order',
      'orderby' => 'meta_value_num',
      'order' => 'ASC'
      )
      ),
      'numberposts' => -1
      ));
      foreach($posts as $post)
      echo get_the_title();




      Snippet 3



      $queried_object = get_queried_object();
      $args = array(
      'post_type' => 'cars',
      'term' => $queried_object->slug,
      'orderby' => 'meta_value_num',
      'order' => 'ASC',
      'meta_key' => 'display_order',
      'meta_query' => array(
      array(
      'key' => 'display_order'
      )
      ),
      'tax_query' => array(
      array(
      'taxonomy' => 'luxury-cars',
      'terms' => array(
      $queried_object->term_id
      )
      )
      )
      );
      $query = new WP_Query($args);

      while ( have_posts() ) : the_post();

      ...






      wordpress while-loop custom-taxonomy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 15:53







      rainerbrunotte

















      asked Mar 22 at 14:03









      rainerbrunotterainerbrunotte

      470725




      470725






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55301332%2fwordpress-sort-custom-taxonomy-posts-by-custom-field-value%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55301332%2fwordpress-sort-custom-taxonomy-posts-by-custom-field-value%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript