Results 1 to 3 of 3

Thread: New database table with Json?

  1. #1
    Tijmen is offline Hello World
    Join Date
    Nov 2011
    Posts
    3

    Default New database table with Json?

    I'm working on my first attempt to make a WordPress plugin. It involves Google Maps and latlong coordinates that need to be stored. People can add it to single posts, but there is also an option to show a big map including all the saved locations where it would draw a route between the locations.

    But having to go through possible hundreds of posts looking for the meta data to draw a route on the big map, every single time someone visits that page, sounds like a bad idea to me.

    So I though of creating a new database table, and store a collection of location and page id's of posts that should be shown on the map in json. So there would be only 1 field, with 1 value in it. I'm aware that if you want to edit json, you need to decode, change, encode and save, but this would only happen in the dashboard, not on the front end.

    Would you say it's better to store possible hunderds of latlng coordinates and page ids in JSON and have only 1 row, or would it be better to create a new row for every id and latlng in a new table? Or is there another easy way to find all the posts from the database that have the meta data set for the latlng value?

    Thanks :)

  2. #2
    andreasnrb's Avatar
    andreasnrb is offline Kegger
    Join Date
    Jun 2009
    Posts
    595

    Default

    Just store it in a transient (see codex) .
    But you don't have to go through tons of posts to get the post meta. You can just get all the meta_values directly.
    PHP Code:
    $locations=get_transiet('your_locations);
    if(!$locations){
    $table = _get_meta_table('
    post');
    $locations=$wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $table WHERE meta_key=%s", $meta_type), ARRAY_A );
    set_transient(,'
    location$locations,60 60*12)//cache for 12 hours


  3. #3
    Tijmen is offline Hello World
    Join Date
    Nov 2011
    Posts
    3

    Default

    Never heard of transient before, but it looks like a good solution for my problem. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •