1

This is the info we have

Bus Name Table

id ,  bus_name
 1      BUS1
 2      BUS2
 3      BUS3

Stop Name Table

id, stop_name
 1    STOP1
 2    STOP2
 3    STOP3
 4    STOP4 
 5    STOP5

Route Table

id, bus_id,  stop_id, arrival_time,   departure_time
  1      1        1        START         0800
  2      1        2        0810          0811 
  3      1        3        0820          0821
  4      1        4        0830          0831 
  5      1        5        0840          END   
  6      2        1        START         0810
  7      2        2        0820          0821 
  8      2        3        0830          0831
  9      2        4        0840          0841 
 10      2        5        0850          END
 11      3        1        START         0820
 12      3        2        0830          0831 
 13      3        3        0840          0841
 14      3        4        0850          0851 
 15      3        5        0900          END     

How to use wordpress CPT to store all this info and when a user searches from stop A to stop B, get results with bus names and their arrival and departure times.

  • 1
    In all honesty I would keep the data as it is if you already have queries for it, writing raw SQL sucks but since you're going to have to write all the search code yourself anyway you might as well stick with what you have – Tom J Nowell Dec 28 '17 at 0:19
0

The native WordPress way would be to register a custom post type for "Routes" and then Taxonomies for "Stops" and "Buses".

Using Custom Fields you can handle the start and end time. You can add Meta Fields to the Post Type, so you don't have to declare the custom fields each time. Here's a tutorial for that: https://premium.wpmudev.org/blog/creating-meta-boxes/

I don't know that WordPress will store it as efficiently as your table structure. Each custom field value will be its own row in the Post Meta table. But, this is the way WordPress is built and they've got it dialed in.

You should be able to use the native search to handle Buses, Routes, and Stops. And any description fields. If you store departure and return times as Custom Fields, you'd need to extend WP Query to look for those. Here's a tutorial: https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.