0

I have JSON results from Google API added to to wp_options table. At this point I just need to echo the specific elements. Namely, the coordinates. The option_name I have is py_menu_item. One of the option_value element is coords. That is what represents the JSON results. The code below yields this response: array(o){}

The code:

global $wpdb;
$myrows = $wpdb->get_results("SELECT * FROM $wpdb->wp_options WHERE option_name = py_menu_item", ARRAY_A");
$lat = $myrows->results[0]->geometry->location->lat;    //latitude
$long = $myrows->results[0]->geometry->location->lng;   //longitude 
echo $lat;
echo $long;
var_dump($myrows);

I am using this Codex page as a guide: Class_Reference/wpdb

3
  • Coords isn't a column in wp_options, is that maybe the meta_key? Dec 6, 2013 at 0:54
  • Coords is an element inside the option_value field. It is an element in my custom row py_menu_item. It is what represents all of the JSON data in the option_value field.
    – user56258
    Dec 6, 2013 at 1:34
  • $wpdb->wp_options doesn't exist, should be $wpdb->options
    – Milo
    Dec 6, 2013 at 3:11

1 Answer 1

1

Don't use SQL to retrieve values from the option table, use the options API. In addition to avoiding using wrong table names (as was pointed out in the comments) you will most likely get better performance.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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