Ordering By Menu Order in the Wordpress REST API?












1















I am trying to display posts using the REST API and I want to display them in menu order based on how they are positioned in the admin menu.



I installed a plugin that allowed me to move posts to any position in the admin. I know querying the posts the normal way with wordpress there is a orderby: menu_order option, which would do what I am looking for, but I can't figure it out with the REST API.



My REST API looks like this:



https://example.com/wp-json/wp/v2/qd_leadership?_embed&per_page=100&orderby=menu_order


So I've tried that and that does not work. It says menu_order isn't an option. I also saw a post here:



Query WordPress (REST) posts by the order they appear on the admin



That had a similar question. The only answer on that post is to not have any orderby parameter and that should display them in the menu order, but that did not work for me. So I am stumped on how to order the posts from the REST API in menu order?










share|improve this question





























    1















    I am trying to display posts using the REST API and I want to display them in menu order based on how they are positioned in the admin menu.



    I installed a plugin that allowed me to move posts to any position in the admin. I know querying the posts the normal way with wordpress there is a orderby: menu_order option, which would do what I am looking for, but I can't figure it out with the REST API.



    My REST API looks like this:



    https://example.com/wp-json/wp/v2/qd_leadership?_embed&per_page=100&orderby=menu_order


    So I've tried that and that does not work. It says menu_order isn't an option. I also saw a post here:



    Query WordPress (REST) posts by the order they appear on the admin



    That had a similar question. The only answer on that post is to not have any orderby parameter and that should display them in the menu order, but that did not work for me. So I am stumped on how to order the posts from the REST API in menu order?










    share|improve this question



























      1












      1








      1








      I am trying to display posts using the REST API and I want to display them in menu order based on how they are positioned in the admin menu.



      I installed a plugin that allowed me to move posts to any position in the admin. I know querying the posts the normal way with wordpress there is a orderby: menu_order option, which would do what I am looking for, but I can't figure it out with the REST API.



      My REST API looks like this:



      https://example.com/wp-json/wp/v2/qd_leadership?_embed&per_page=100&orderby=menu_order


      So I've tried that and that does not work. It says menu_order isn't an option. I also saw a post here:



      Query WordPress (REST) posts by the order they appear on the admin



      That had a similar question. The only answer on that post is to not have any orderby parameter and that should display them in the menu order, but that did not work for me. So I am stumped on how to order the posts from the REST API in menu order?










      share|improve this question
















      I am trying to display posts using the REST API and I want to display them in menu order based on how they are positioned in the admin menu.



      I installed a plugin that allowed me to move posts to any position in the admin. I know querying the posts the normal way with wordpress there is a orderby: menu_order option, which would do what I am looking for, but I can't figure it out with the REST API.



      My REST API looks like this:



      https://example.com/wp-json/wp/v2/qd_leadership?_embed&per_page=100&orderby=menu_order


      So I've tried that and that does not work. It says menu_order isn't an option. I also saw a post here:



      Query WordPress (REST) posts by the order they appear on the admin



      That had a similar question. The only answer on that post is to not have any orderby parameter and that should display them in the menu order, but that did not work for me. So I am stumped on how to order the posts from the REST API in menu order?







      wordpress sorting wordpress-rest-api






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 23 at 6:40









      Ilya Berdichevsky

      527318




      527318










      asked Jan 18 at 20:00









      user9664977user9664977

      589




      589
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Its bug of wp core in rest api so you could use below hack for the solution.Please add below code in your active theme's function.php



          add_filter( 'rest_post_collection_params', 'my_prefix_add_rest_orderby_params', 10, 1 );

          function my_prefix_add_rest_orderby_params( $params ) {
          $params['orderby']['enum'] = 'menu_order';

          return $params;
          }


          Tested and works.






          share|improve this answer
























          • works perfectly thank you!

            – user9664977
            Jan 21 at 18:33











          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%2f54260699%2fordering-by-menu-order-in-the-wordpress-rest-api%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









          0














          Its bug of wp core in rest api so you could use below hack for the solution.Please add below code in your active theme's function.php



          add_filter( 'rest_post_collection_params', 'my_prefix_add_rest_orderby_params', 10, 1 );

          function my_prefix_add_rest_orderby_params( $params ) {
          $params['orderby']['enum'] = 'menu_order';

          return $params;
          }


          Tested and works.






          share|improve this answer
























          • works perfectly thank you!

            – user9664977
            Jan 21 at 18:33
















          0














          Its bug of wp core in rest api so you could use below hack for the solution.Please add below code in your active theme's function.php



          add_filter( 'rest_post_collection_params', 'my_prefix_add_rest_orderby_params', 10, 1 );

          function my_prefix_add_rest_orderby_params( $params ) {
          $params['orderby']['enum'] = 'menu_order';

          return $params;
          }


          Tested and works.






          share|improve this answer
























          • works perfectly thank you!

            – user9664977
            Jan 21 at 18:33














          0












          0








          0







          Its bug of wp core in rest api so you could use below hack for the solution.Please add below code in your active theme's function.php



          add_filter( 'rest_post_collection_params', 'my_prefix_add_rest_orderby_params', 10, 1 );

          function my_prefix_add_rest_orderby_params( $params ) {
          $params['orderby']['enum'] = 'menu_order';

          return $params;
          }


          Tested and works.






          share|improve this answer













          Its bug of wp core in rest api so you could use below hack for the solution.Please add below code in your active theme's function.php



          add_filter( 'rest_post_collection_params', 'my_prefix_add_rest_orderby_params', 10, 1 );

          function my_prefix_add_rest_orderby_params( $params ) {
          $params['orderby']['enum'] = 'menu_order';

          return $params;
          }


          Tested and works.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 19 at 8:01









          raju_ewwraju_eww

          644315




          644315













          • works perfectly thank you!

            – user9664977
            Jan 21 at 18:33



















          • works perfectly thank you!

            – user9664977
            Jan 21 at 18:33

















          works perfectly thank you!

          – user9664977
          Jan 21 at 18:33





          works perfectly thank you!

          – user9664977
          Jan 21 at 18:33


















          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%2f54260699%2fordering-by-menu-order-in-the-wordpress-rest-api%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

          Liquibase includeAll doesn't find base path

          How to use setInterval in EJS file?

          Petrus Granier-Deferre