Order custom wordpress loop










0















I have a WordPress custom loop which looks like this:



$args = array( 
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'meta_key' => 'publication_type',
'meta_value' => 'uma',
);


This shows 6 posts with publication_type equal to "uma". The publication_type is a field created with Advanced Custom Fields.



I've also created the field publication_year which contains 2019, 2018, 2017,...



How is it possible to order all my posts descending?



The following example doesn't do a thing:



$args = array( 
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'order_by' => 'publication_year',
'order' => 'DESC'
'meta_key' => 'publication_type',
'meta_value' => 'uma',
);









share|improve this question




























    0















    I have a WordPress custom loop which looks like this:



    $args = array( 
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 6,
    'meta_key' => 'publication_type',
    'meta_value' => 'uma',
    );


    This shows 6 posts with publication_type equal to "uma". The publication_type is a field created with Advanced Custom Fields.



    I've also created the field publication_year which contains 2019, 2018, 2017,...



    How is it possible to order all my posts descending?



    The following example doesn't do a thing:



    $args = array( 
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 6,
    'order_by' => 'publication_year',
    'order' => 'DESC'
    'meta_key' => 'publication_type',
    'meta_value' => 'uma',
    );









    share|improve this question


























      0












      0








      0








      I have a WordPress custom loop which looks like this:



      $args = array( 
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 6,
      'meta_key' => 'publication_type',
      'meta_value' => 'uma',
      );


      This shows 6 posts with publication_type equal to "uma". The publication_type is a field created with Advanced Custom Fields.



      I've also created the field publication_year which contains 2019, 2018, 2017,...



      How is it possible to order all my posts descending?



      The following example doesn't do a thing:



      $args = array( 
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 6,
      'order_by' => 'publication_year',
      'order' => 'DESC'
      'meta_key' => 'publication_type',
      'meta_value' => 'uma',
      );









      share|improve this question
















      I have a WordPress custom loop which looks like this:



      $args = array( 
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 6,
      'meta_key' => 'publication_type',
      'meta_value' => 'uma',
      );


      This shows 6 posts with publication_type equal to "uma". The publication_type is a field created with Advanced Custom Fields.



      I've also created the field publication_year which contains 2019, 2018, 2017,...



      How is it possible to order all my posts descending?



      The following example doesn't do a thing:



      $args = array( 
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 6,
      'order_by' => 'publication_year',
      'order' => 'DESC'
      'meta_key' => 'publication_type',
      'meta_value' => 'uma',
      );






      wordpress loops






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 8:35









      Gufran Hasan

      3,62741527




      3,62741527










      asked Nov 15 '18 at 7:06









      Dennis PerremansDennis Perremans

      15211




      15211






















          1 Answer
          1






          active

          oldest

          votes


















          1














           $args = new WP_Query( array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'meta_query' => array(
          array(
          'key' => 'publication_type',
          'value' => 'uma',
          ),
          ),
          'meta_key' => 'publication_year',
          'orderby' => 'meta_value_num',
          'order' => 'ASC',
          ));





          share|improve this answer

























          • Sorry this doesn’t work. This gives more Posts then there are under publication_type=“uma”

            – Dennis Perremans
            Nov 15 '18 at 8:27











          • @DennisPerremans I edited my above code. please check now.make sure your meta_key name is correct.

            – Krishna thakor
            Nov 15 '18 at 8:41












          • No sorry, it still shows posts with publication_type="member" and publication_type="press".

            – Dennis Perremans
            Nov 15 '18 at 9:23











          • @DennisPerremans R u sure you stored custom field with name 'publication_type' because there is nothing wrong with this code it is working fine for me. I test it.Please reverify your field name and check its value in database. because here it is not taking 'publication_type' value that's why the problem occurs.

            – Krishna thakor
            Nov 15 '18 at 9:26












          • Yes, I can assure you that the correct field name is "publication_type" which is a select. And "publication_year" is a numeric field. I've double checked it by printing the values for these custom fields.

            – Dennis Perremans
            Nov 15 '18 at 10:05










          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%2f53314088%2forder-custom-wordpress-loop%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














           $args = new WP_Query( array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'meta_query' => array(
          array(
          'key' => 'publication_type',
          'value' => 'uma',
          ),
          ),
          'meta_key' => 'publication_year',
          'orderby' => 'meta_value_num',
          'order' => 'ASC',
          ));





          share|improve this answer

























          • Sorry this doesn’t work. This gives more Posts then there are under publication_type=“uma”

            – Dennis Perremans
            Nov 15 '18 at 8:27











          • @DennisPerremans I edited my above code. please check now.make sure your meta_key name is correct.

            – Krishna thakor
            Nov 15 '18 at 8:41












          • No sorry, it still shows posts with publication_type="member" and publication_type="press".

            – Dennis Perremans
            Nov 15 '18 at 9:23











          • @DennisPerremans R u sure you stored custom field with name 'publication_type' because there is nothing wrong with this code it is working fine for me. I test it.Please reverify your field name and check its value in database. because here it is not taking 'publication_type' value that's why the problem occurs.

            – Krishna thakor
            Nov 15 '18 at 9:26












          • Yes, I can assure you that the correct field name is "publication_type" which is a select. And "publication_year" is a numeric field. I've double checked it by printing the values for these custom fields.

            – Dennis Perremans
            Nov 15 '18 at 10:05















          1














           $args = new WP_Query( array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'meta_query' => array(
          array(
          'key' => 'publication_type',
          'value' => 'uma',
          ),
          ),
          'meta_key' => 'publication_year',
          'orderby' => 'meta_value_num',
          'order' => 'ASC',
          ));





          share|improve this answer

























          • Sorry this doesn’t work. This gives more Posts then there are under publication_type=“uma”

            – Dennis Perremans
            Nov 15 '18 at 8:27











          • @DennisPerremans I edited my above code. please check now.make sure your meta_key name is correct.

            – Krishna thakor
            Nov 15 '18 at 8:41












          • No sorry, it still shows posts with publication_type="member" and publication_type="press".

            – Dennis Perremans
            Nov 15 '18 at 9:23











          • @DennisPerremans R u sure you stored custom field with name 'publication_type' because there is nothing wrong with this code it is working fine for me. I test it.Please reverify your field name and check its value in database. because here it is not taking 'publication_type' value that's why the problem occurs.

            – Krishna thakor
            Nov 15 '18 at 9:26












          • Yes, I can assure you that the correct field name is "publication_type" which is a select. And "publication_year" is a numeric field. I've double checked it by printing the values for these custom fields.

            – Dennis Perremans
            Nov 15 '18 at 10:05













          1












          1








          1







           $args = new WP_Query( array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'meta_query' => array(
          array(
          'key' => 'publication_type',
          'value' => 'uma',
          ),
          ),
          'meta_key' => 'publication_year',
          'orderby' => 'meta_value_num',
          'order' => 'ASC',
          ));





          share|improve this answer















           $args = new WP_Query( array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'meta_query' => array(
          array(
          'key' => 'publication_type',
          'value' => 'uma',
          ),
          ),
          'meta_key' => 'publication_year',
          'orderby' => 'meta_value_num',
          'order' => 'ASC',
          ));






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '18 at 14:51









          utsav tilava

          201




          201










          answered Nov 15 '18 at 8:07









          Krishna thakorKrishna thakor

          10010




          10010












          • Sorry this doesn’t work. This gives more Posts then there are under publication_type=“uma”

            – Dennis Perremans
            Nov 15 '18 at 8:27











          • @DennisPerremans I edited my above code. please check now.make sure your meta_key name is correct.

            – Krishna thakor
            Nov 15 '18 at 8:41












          • No sorry, it still shows posts with publication_type="member" and publication_type="press".

            – Dennis Perremans
            Nov 15 '18 at 9:23











          • @DennisPerremans R u sure you stored custom field with name 'publication_type' because there is nothing wrong with this code it is working fine for me. I test it.Please reverify your field name and check its value in database. because here it is not taking 'publication_type' value that's why the problem occurs.

            – Krishna thakor
            Nov 15 '18 at 9:26












          • Yes, I can assure you that the correct field name is "publication_type" which is a select. And "publication_year" is a numeric field. I've double checked it by printing the values for these custom fields.

            – Dennis Perremans
            Nov 15 '18 at 10:05

















          • Sorry this doesn’t work. This gives more Posts then there are under publication_type=“uma”

            – Dennis Perremans
            Nov 15 '18 at 8:27











          • @DennisPerremans I edited my above code. please check now.make sure your meta_key name is correct.

            – Krishna thakor
            Nov 15 '18 at 8:41












          • No sorry, it still shows posts with publication_type="member" and publication_type="press".

            – Dennis Perremans
            Nov 15 '18 at 9:23











          • @DennisPerremans R u sure you stored custom field with name 'publication_type' because there is nothing wrong with this code it is working fine for me. I test it.Please reverify your field name and check its value in database. because here it is not taking 'publication_type' value that's why the problem occurs.

            – Krishna thakor
            Nov 15 '18 at 9:26












          • Yes, I can assure you that the correct field name is "publication_type" which is a select. And "publication_year" is a numeric field. I've double checked it by printing the values for these custom fields.

            – Dennis Perremans
            Nov 15 '18 at 10:05
















          Sorry this doesn’t work. This gives more Posts then there are under publication_type=“uma”

          – Dennis Perremans
          Nov 15 '18 at 8:27





          Sorry this doesn’t work. This gives more Posts then there are under publication_type=“uma”

          – Dennis Perremans
          Nov 15 '18 at 8:27













          @DennisPerremans I edited my above code. please check now.make sure your meta_key name is correct.

          – Krishna thakor
          Nov 15 '18 at 8:41






          @DennisPerremans I edited my above code. please check now.make sure your meta_key name is correct.

          – Krishna thakor
          Nov 15 '18 at 8:41














          No sorry, it still shows posts with publication_type="member" and publication_type="press".

          – Dennis Perremans
          Nov 15 '18 at 9:23





          No sorry, it still shows posts with publication_type="member" and publication_type="press".

          – Dennis Perremans
          Nov 15 '18 at 9:23













          @DennisPerremans R u sure you stored custom field with name 'publication_type' because there is nothing wrong with this code it is working fine for me. I test it.Please reverify your field name and check its value in database. because here it is not taking 'publication_type' value that's why the problem occurs.

          – Krishna thakor
          Nov 15 '18 at 9:26






          @DennisPerremans R u sure you stored custom field with name 'publication_type' because there is nothing wrong with this code it is working fine for me. I test it.Please reverify your field name and check its value in database. because here it is not taking 'publication_type' value that's why the problem occurs.

          – Krishna thakor
          Nov 15 '18 at 9:26














          Yes, I can assure you that the correct field name is "publication_type" which is a select. And "publication_year" is a numeric field. I've double checked it by printing the values for these custom fields.

          – Dennis Perremans
          Nov 15 '18 at 10:05





          Yes, I can assure you that the correct field name is "publication_type" which is a select. And "publication_year" is a numeric field. I've double checked it by printing the values for these custom fields.

          – Dennis Perremans
          Nov 15 '18 at 10:05



















          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%2f53314088%2forder-custom-wordpress-loop%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







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto