I am working with a Wordpress site and have created a custom page in /home/planmyme/public_html/php/
with the name response.php
. On this page I am getting a value to insert in the wp_postmeta
table (value examples: transaction ID, purchase ID, order ID, or item name), but I am not able to insert it.
I am using the code below as a test. I do not understand how to achieve this, or if there is any need of a database connection to run the query.
$metakey = "_menu_item_type";
$metavalue = "WordPress' database interface is like Sunday Morning: Easy.";
$wpdb->query( $wpdb->prepare(
"
INSERT INTO $wpdb->wp_postmeta
( post_id, meta_key, meta_value )
VALUES ( %d, %s, %s )
",
10,
$metakey,
$metavalue
) );
Getting this error
Fatal error: Call to a member function query() on a non-object in /home/planmyme/public_html/php/response.php on line 56
If anybody has an idea how to do this, please let me know.
WP_USE_THEMES
on this site to find out how to include WordPress in an external script. But why don't you include your script directly into WordPress via plugin or a page template?