Should I make a new database field and use JSON?
I’m trying to make my first wp plugin. But I ran into an issue where I’m not sure which option to take.
It involves latlng coordinates for Google maps that are stored as meta data for each post. This works fine, but there is also a big map where all the locations for all posts are shown.
Not every post has to include Google maps, so the meta data with the latlng data might not always exist. Going through every single post in the database just to see if the meta data for Google maps exists doesn’t sound like the most efficient way to handle this.
So I thought to just create a new database field, with only 1 field that holds all the id’s for posts that have a Google maps in it in json format.
When the big map is loaded, it only takes 1 request to get the list of id’s. Then I would still need to load the meta data, but there is no need anymore to go through every single post to check if Google maps should be shown or not.
Also, another thing I thought of was to not only store the id of the pages, but also the latlng value and the page title in new database field in json. Because on the map, the plan is to click on the marker, and then show the title and link to the corresponding post. This should save quite a few db queries on the front-end.
I’m aware that if you want to edit json data you need to decode, modify, encode, save. But that would only happen in the admin panel.
Would it be a bad idea to go with the json option, and just use a new database field to store just the page id’s I need? Or should I be looking at a very different way of handling this.
- The topic ‘Should I make a new database field and use JSON?’ is closed to new replies.