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? Commented 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. Commented Dec 6, 2013 at 1:34
  • $wpdb->wp_options doesn't exist, should be $wpdb->options Commented 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 you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.