Create Pages from DatabaseHow to create a php url redirection for nicer linksQuery the database after get_header() has been includedApply template to custom post typeHow to create custom layouts and static pages in themes for clientsCreate pages from MySQL databaseCreating custom page template from existing PHP siteStringing together content from different databasesNeed to create a custom page on a websiteNew entries to custom post type produce 404 on single view

Writing a letter of recommendation for a mediocre student

A drug that allows people to survive on less food

How use custom order in folder on Windows 7 and 10

I reverse the source code, you negate the input!

How does IBM's 53-bit quantum computer compare to classical ones for cryptanalytic tasks?

Why is there not a feasible solution for a MIP?

Social leper versus social leopard

Does a GFCI-protected bath light/fan unit need separate neutrals?

Can this word order be rearranged?

Late 1970's and 6502 chip facilities for operating systems

Is it impolite to ask for halal food when traveling to and in Thailand?

To what extent is it worthwhile to report check fraud / refund scams?

Guitar tuning (EADGBE), "perfect" fourths?

What can a pilot do if an air traffic controller is incapacitated?

Cut a cake into 3 equal portions with only a knife

Leaving a job that I just took based on false promise of a raise. What do I tell future interviewers?

What are these ingforms of learning?

Resolving moral conflict

Examples of "unsuccessful" theories with afterlives

What is the meaning of "heutig" in this sentence?

Is this a Sherman, and if so what model?

Transforming 2D points on to a regular grid or lattice

A high quality contribution but an annoying error is present in my published article

Hilbert's hotel, why can't I repeat it infinitely many times?



Create Pages from Database


How to create a php url redirection for nicer linksQuery the database after get_header() has been includedApply template to custom post typeHow to create custom layouts and static pages in themes for clientsCreate pages from MySQL databaseCreating custom page template from existing PHP siteStringing together content from different databasesNeed to create a custom page on a websiteNew entries to custom post type produce 404 on single view






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















i've recently decided to create a website with wordpress.



My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.



But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.



Is there some way to dynamically create a page based of a template after the user searched for it?










share|improve this question






























    1















    i've recently decided to create a website with wordpress.



    My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.



    But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.



    Is there some way to dynamically create a page based of a template after the user searched for it?










    share|improve this question


























      1












      1








      1


      1






      i've recently decided to create a website with wordpress.



      My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.



      But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.



      Is there some way to dynamically create a page based of a template after the user searched for it?










      share|improve this question














      i've recently decided to create a website with wordpress.



      My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.



      But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.



      Is there some way to dynamically create a page based of a template after the user searched for it?







      custom-post-types database templates mysql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 15 at 10:21









      QUEQUE

      61 bronze badge




      61 bronze badge























          2 Answers
          2






          active

          oldest

          votes


















          3
















          There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.



          Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)



          There's a little more information on setting up the redirects in this answer of mine.






          share|improve this answer
































            2
















            You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.



            The following sample adds a new custom template suggestion. So that always when the URL contains foobar as first segment and a non-empty second segment the foobar.php template from your current theme will be rendered.



            add_action('template_include', 'template_suggestions');
            function template_suggestions($template)

            $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
            $foobar_template = locate_template(['foobar.php']);

            if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')

            status_header(200);
            return $foobar_template;


            return $template;



            Now use any other custom function to return your database query results.



            function foobar_results() 

            $myrows = [];
            $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

            if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')

            global $wpdb;
            $myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );


            return $myrows;



            And then in foobar.php simply loop through the results.



            <?php foreach(foobar_results() as $row): ?>
            <?php print $row->id; ?>
            <?php endforeach; ?>





            share|improve this answer



























              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "110"
              ;
              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: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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/4.0/"u003ecc by-sa 4.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%2fwordpress.stackexchange.com%2fquestions%2f334410%2fcreate-pages-from-database%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3
















              There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.



              Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)



              There's a little more information on setting up the redirects in this answer of mine.






              share|improve this answer





























                3
















                There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.



                Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)



                There's a little more information on setting up the redirects in this answer of mine.






                share|improve this answer



























                  3














                  3










                  3









                  There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.



                  Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)



                  There's a little more information on setting up the redirects in this answer of mine.






                  share|improve this answer













                  There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.



                  Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)



                  There's a little more information on setting up the redirects in this answer of mine.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 15 at 10:30









                  Alexander HolsgroveAlexander Holsgrove

                  1,4561 gold badge9 silver badges17 bronze badges




                  1,4561 gold badge9 silver badges17 bronze badges


























                      2
















                      You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.



                      The following sample adds a new custom template suggestion. So that always when the URL contains foobar as first segment and a non-empty second segment the foobar.php template from your current theme will be rendered.



                      add_action('template_include', 'template_suggestions');
                      function template_suggestions($template)

                      $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
                      $foobar_template = locate_template(['foobar.php']);

                      if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')

                      status_header(200);
                      return $foobar_template;


                      return $template;



                      Now use any other custom function to return your database query results.



                      function foobar_results() 

                      $myrows = [];
                      $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

                      if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')

                      global $wpdb;
                      $myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );


                      return $myrows;



                      And then in foobar.php simply loop through the results.



                      <?php foreach(foobar_results() as $row): ?>
                      <?php print $row->id; ?>
                      <?php endforeach; ?>





                      share|improve this answer





























                        2
















                        You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.



                        The following sample adds a new custom template suggestion. So that always when the URL contains foobar as first segment and a non-empty second segment the foobar.php template from your current theme will be rendered.



                        add_action('template_include', 'template_suggestions');
                        function template_suggestions($template)

                        $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
                        $foobar_template = locate_template(['foobar.php']);

                        if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')

                        status_header(200);
                        return $foobar_template;


                        return $template;



                        Now use any other custom function to return your database query results.



                        function foobar_results() 

                        $myrows = [];
                        $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

                        if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')

                        global $wpdb;
                        $myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );


                        return $myrows;



                        And then in foobar.php simply loop through the results.



                        <?php foreach(foobar_results() as $row): ?>
                        <?php print $row->id; ?>
                        <?php endforeach; ?>





                        share|improve this answer



























                          2














                          2










                          2









                          You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.



                          The following sample adds a new custom template suggestion. So that always when the URL contains foobar as first segment and a non-empty second segment the foobar.php template from your current theme will be rendered.



                          add_action('template_include', 'template_suggestions');
                          function template_suggestions($template)

                          $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
                          $foobar_template = locate_template(['foobar.php']);

                          if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')

                          status_header(200);
                          return $foobar_template;


                          return $template;



                          Now use any other custom function to return your database query results.



                          function foobar_results() 

                          $myrows = [];
                          $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

                          if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')

                          global $wpdb;
                          $myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );


                          return $myrows;



                          And then in foobar.php simply loop through the results.



                          <?php foreach(foobar_results() as $row): ?>
                          <?php print $row->id; ?>
                          <?php endforeach; ?>





                          share|improve this answer













                          You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.



                          The following sample adds a new custom template suggestion. So that always when the URL contains foobar as first segment and a non-empty second segment the foobar.php template from your current theme will be rendered.



                          add_action('template_include', 'template_suggestions');
                          function template_suggestions($template)

                          $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
                          $foobar_template = locate_template(['foobar.php']);

                          if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')

                          status_header(200);
                          return $foobar_template;


                          return $template;



                          Now use any other custom function to return your database query results.



                          function foobar_results() 

                          $myrows = [];
                          $segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

                          if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')

                          global $wpdb;
                          $myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );


                          return $myrows;



                          And then in foobar.php simply loop through the results.



                          <?php foreach(foobar_results() as $row): ?>
                          <?php print $row->id; ?>
                          <?php endforeach; ?>






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 15 at 11:11









                          leymannxleymannx

                          1,6512 gold badges16 silver badges27 bronze badges




                          1,6512 gold badges16 silver badges27 bronze badges































                              draft saved

                              draft discarded















































                              Thanks for contributing an answer to WordPress Development Stack Exchange!


                              • 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%2fwordpress.stackexchange.com%2fquestions%2f334410%2fcreate-pages-from-database%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

                              Tamil (spriik) Luke uk diar | Nawigatjuun

                              Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                              Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?