• I am creating a website that has a page for continents/regions. When you click on one continent, it should take you to a page that shows a list of countries. If you click on a country, it takes you to a page that lists cities in that country. I think it’s a bad idea to create over 500 new pages. How do you pull this data from the database tables and display it as loop for each country?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could use Custom Post Type, so you won’t have to create 500 pages. Check the details here: https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/

    Here is a rough idea for you:

    1. Set up a custom post type for “City” and custom taxonomies for “Country” and “Continent” in your functions.php.
    2. Add cities, countries, and continents in the WordPress admin, assigning the right taxonomies.
    3. Design templates for showing continents, countries (by continent), and cities (by country). Use loops with get_terms() or WP_Query to fetch and display the data.

    Thread Starter mo505050

    (@mo505050)

    Thank you for the reply.

    I am still stuck on the solution. When I write the code for the custom post type and custom taxonomy and add it to the ‘functions.php’ , I get an error on the dashboard. I am using EasyWP on namecheap. Is there any other way to add it? The website is already live

    You may use the Custom Post Type UI plugin to create CPT without writing custom code. Give it a try, and let me know how that goes!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Accessing data from database and display on multiple pages’ is closed to new replies.