How do you work with database meta key and values?How to get WooCommerce order detailsHow does database indexing work?How to list the tables in a SQLite database file that was opened with ATTACH?How to temporarily disable a foreign key constraint in MySQL?SQL query to retrieve taxonomy of product in WoocommerceSQL query should not return rows that contain null values in pivot tableSQL query to get custom post type and optional taxonomiesWhich is the correlation between an ORDER and the USER who bought in WooCommerce/WordPress databaseImport orders from excel file in woocommerceGet seperate keys and values from string where all data is inlineSort by Meta Value with mixing Custom Post Type in WordPress
Were Roman public roads build by private companies?
Is "you will become a subject matter expert" code for "you'll be working on your own 100% of the time"?
How can I discourage sharing internal API keys within a company?
Will the UK home office know about 5 previous visa rejections in other countries?
What was the ultimate objective of The Party in 1984?
What is my breathable atmosphere composed of?
What are uses of the byte after BRK instruction on 6502?
Why is this weapon searching for a new owner?
What does a Light weapon mean mechanically?
I asked for a graduate student position from a professor. He replied "welcome". What does that mean?
Are space camera sensors usually round, or square?
Is there any reason to concentrate on the Thunderous Smite spell after using its effects?
Can I tap all my opponent's lands while they're casting a spell to negate it?
Why don't Wizards use wrist straps to protect against disarming charms?
Asked to Not Use Transactions and to Use A Workaround to Simulate One
Asking students to define "unique"
Newly created XFS filesystem shows 78 GB used
Can you add polynomial terms to multiple linear regression?
Can I fix my boots by gluing the soles back on?
What was the motivation for the invention of electric pianos?
Why do sellers care about down payments?
How to stabilise the bicycle seatpost and saddle when it is all the way up?
How would you control supersoldiers in a late iron-age society?
Double it your way
How do you work with database meta key and values?
How to get WooCommerce order detailsHow does database indexing work?How to list the tables in a SQLite database file that was opened with ATTACH?How to temporarily disable a foreign key constraint in MySQL?SQL query to retrieve taxonomy of product in WoocommerceSQL query should not return rows that contain null values in pivot tableSQL query to get custom post type and optional taxonomiesWhich is the correlation between an ORDER and the USER who bought in WooCommerce/WordPress databaseImport orders from excel file in woocommerceGet seperate keys and values from string where all data is inlineSort by Meta Value with mixing Custom Post Type in WordPress
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I’m trying to use SQL to retrieve Woocommerce order item meta keys and values so that I can summarise the information in my own report, but I am really struggling to extract meta keys and values as columns. Could anyone provide any SQL examples? Is there a Wordpress API I can use for metadata?
I have tried creating the following SQL as a basis for extending the query for product information. It returns the right kind of data but only a single row:
SELECT O.order_item_id, O.order_item_name,
MAX(IF(OIM.meta_key = 'class', OIM.meta_value, NULL)) AS class
FROM wp_woocommerce_order_items AS O
LEFT JOIN wp_woocommerce_order_itemmeta AS OIM on O.order_item_id =
OIM.order_item_id
WHERE O.order_item_name='Smiths Night School';
Thanks
sql wordpress woocommerce
|
show 4 more comments
I’m trying to use SQL to retrieve Woocommerce order item meta keys and values so that I can summarise the information in my own report, but I am really struggling to extract meta keys and values as columns. Could anyone provide any SQL examples? Is there a Wordpress API I can use for metadata?
I have tried creating the following SQL as a basis for extending the query for product information. It returns the right kind of data but only a single row:
SELECT O.order_item_id, O.order_item_name,
MAX(IF(OIM.meta_key = 'class', OIM.meta_value, NULL)) AS class
FROM wp_woocommerce_order_items AS O
LEFT JOIN wp_woocommerce_order_itemmeta AS OIM on O.order_item_id =
OIM.order_item_id
WHERE O.order_item_name='Smiths Night School';
Thanks
sql wordpress woocommerce
There is a cool search console named Google which returns you an array with > 440.000 entries when you search for this topic. ;)
– Mr. Jo
Mar 28 at 10:11
Thanks for that incredibly unhelpful response. I have Googled the topic extensively and asked for help on forums without any answer.
– John Smith
Mar 28 at 10:17
Have you checked WooCommerce's documentation already? There must be a function for this already.
– cabrerahector
Mar 28 at 10:21
1
Because these are basics of WordPress development mate. For example when I search for: WordPress select from database: codex.wordpress.org/Class_Reference/wpdb. So this is the basic thing. WooCommerce implemented this for you so you can use functions to get order item values by keys. (see the documentation or search on SO): stackoverflow.com/questions/39401393/…
– Mr. Jo
Mar 28 at 10:23
1
Possible duplicate of How to get WooCommerce order details
– Mr. Jo
Mar 28 at 10:24
|
show 4 more comments
I’m trying to use SQL to retrieve Woocommerce order item meta keys and values so that I can summarise the information in my own report, but I am really struggling to extract meta keys and values as columns. Could anyone provide any SQL examples? Is there a Wordpress API I can use for metadata?
I have tried creating the following SQL as a basis for extending the query for product information. It returns the right kind of data but only a single row:
SELECT O.order_item_id, O.order_item_name,
MAX(IF(OIM.meta_key = 'class', OIM.meta_value, NULL)) AS class
FROM wp_woocommerce_order_items AS O
LEFT JOIN wp_woocommerce_order_itemmeta AS OIM on O.order_item_id =
OIM.order_item_id
WHERE O.order_item_name='Smiths Night School';
Thanks
sql wordpress woocommerce
I’m trying to use SQL to retrieve Woocommerce order item meta keys and values so that I can summarise the information in my own report, but I am really struggling to extract meta keys and values as columns. Could anyone provide any SQL examples? Is there a Wordpress API I can use for metadata?
I have tried creating the following SQL as a basis for extending the query for product information. It returns the right kind of data but only a single row:
SELECT O.order_item_id, O.order_item_name,
MAX(IF(OIM.meta_key = 'class', OIM.meta_value, NULL)) AS class
FROM wp_woocommerce_order_items AS O
LEFT JOIN wp_woocommerce_order_itemmeta AS OIM on O.order_item_id =
OIM.order_item_id
WHERE O.order_item_name='Smiths Night School';
Thanks
sql wordpress woocommerce
sql wordpress woocommerce
edited Mar 28 at 10:24
John Smith
asked Mar 28 at 9:49
John SmithJohn Smith
11610 bronze badges
11610 bronze badges
There is a cool search console named Google which returns you an array with > 440.000 entries when you search for this topic. ;)
– Mr. Jo
Mar 28 at 10:11
Thanks for that incredibly unhelpful response. I have Googled the topic extensively and asked for help on forums without any answer.
– John Smith
Mar 28 at 10:17
Have you checked WooCommerce's documentation already? There must be a function for this already.
– cabrerahector
Mar 28 at 10:21
1
Because these are basics of WordPress development mate. For example when I search for: WordPress select from database: codex.wordpress.org/Class_Reference/wpdb. So this is the basic thing. WooCommerce implemented this for you so you can use functions to get order item values by keys. (see the documentation or search on SO): stackoverflow.com/questions/39401393/…
– Mr. Jo
Mar 28 at 10:23
1
Possible duplicate of How to get WooCommerce order details
– Mr. Jo
Mar 28 at 10:24
|
show 4 more comments
There is a cool search console named Google which returns you an array with > 440.000 entries when you search for this topic. ;)
– Mr. Jo
Mar 28 at 10:11
Thanks for that incredibly unhelpful response. I have Googled the topic extensively and asked for help on forums without any answer.
– John Smith
Mar 28 at 10:17
Have you checked WooCommerce's documentation already? There must be a function for this already.
– cabrerahector
Mar 28 at 10:21
1
Because these are basics of WordPress development mate. For example when I search for: WordPress select from database: codex.wordpress.org/Class_Reference/wpdb. So this is the basic thing. WooCommerce implemented this for you so you can use functions to get order item values by keys. (see the documentation or search on SO): stackoverflow.com/questions/39401393/…
– Mr. Jo
Mar 28 at 10:23
1
Possible duplicate of How to get WooCommerce order details
– Mr. Jo
Mar 28 at 10:24
There is a cool search console named Google which returns you an array with > 440.000 entries when you search for this topic. ;)
– Mr. Jo
Mar 28 at 10:11
There is a cool search console named Google which returns you an array with > 440.000 entries when you search for this topic. ;)
– Mr. Jo
Mar 28 at 10:11
Thanks for that incredibly unhelpful response. I have Googled the topic extensively and asked for help on forums without any answer.
– John Smith
Mar 28 at 10:17
Thanks for that incredibly unhelpful response. I have Googled the topic extensively and asked for help on forums without any answer.
– John Smith
Mar 28 at 10:17
Have you checked WooCommerce's documentation already? There must be a function for this already.
– cabrerahector
Mar 28 at 10:21
Have you checked WooCommerce's documentation already? There must be a function for this already.
– cabrerahector
Mar 28 at 10:21
1
1
Because these are basics of WordPress development mate. For example when I search for: WordPress select from database: codex.wordpress.org/Class_Reference/wpdb. So this is the basic thing. WooCommerce implemented this for you so you can use functions to get order item values by keys. (see the documentation or search on SO): stackoverflow.com/questions/39401393/…
– Mr. Jo
Mar 28 at 10:23
Because these are basics of WordPress development mate. For example when I search for: WordPress select from database: codex.wordpress.org/Class_Reference/wpdb. So this is the basic thing. WooCommerce implemented this for you so you can use functions to get order item values by keys. (see the documentation or search on SO): stackoverflow.com/questions/39401393/…
– Mr. Jo
Mar 28 at 10:23
1
1
Possible duplicate of How to get WooCommerce order details
– Mr. Jo
Mar 28 at 10:24
Possible duplicate of How to get WooCommerce order details
– Mr. Jo
Mar 28 at 10:24
|
show 4 more comments
2 Answers
2
active
oldest
votes
I'm glad that you got it! This is the best way to learn things. To help you a bit, I'll show you the correct way to do this in WordPress (PHP):
<?php
//DB
global $wpdb;
//Get results from the database
$results = $wpdb->get_results( "SELECT O.order_item_id, O.order_item_name, MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class', MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees' FROM wp_woocommerce_order_items O INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id WHERE O.order_item_name='Smiths Night School' GROUP BY O.order_item_id, O.order_item_name" );
foreach ( $results as $result )
echo $result->your_field_from_the_table;
WordPress defines a class called wpdb
, which contains a set of functions used to interact with a database. It's a good way using this class, because it's simple and save.
You also don't need to define your password
and user
of the database within any PHP file (What you need to do if you use the PHP database functionality). If you use wpdb
, this information comes directly out of the wp-config.php
file which is a bit more safe.
add a comment
|
The following code works well. This query returns class and fee-type information for every order_item_name of "Smiths Night School".
SELECT
O.order_item_id, O.order_item_name,
MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class',
MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees'
FROM wp_woocommerce_order_items O
INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id
WHERE O.order_item_name='Smiths Night School'
GROUP BY O.order_item_id, O.order_item_name
If you want to do this now in WordPress, you can check my answer.
– Mr. Jo
Mar 28 at 12:26
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394547%2fhow-do-you-work-with-database-meta-key-and-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm glad that you got it! This is the best way to learn things. To help you a bit, I'll show you the correct way to do this in WordPress (PHP):
<?php
//DB
global $wpdb;
//Get results from the database
$results = $wpdb->get_results( "SELECT O.order_item_id, O.order_item_name, MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class', MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees' FROM wp_woocommerce_order_items O INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id WHERE O.order_item_name='Smiths Night School' GROUP BY O.order_item_id, O.order_item_name" );
foreach ( $results as $result )
echo $result->your_field_from_the_table;
WordPress defines a class called wpdb
, which contains a set of functions used to interact with a database. It's a good way using this class, because it's simple and save.
You also don't need to define your password
and user
of the database within any PHP file (What you need to do if you use the PHP database functionality). If you use wpdb
, this information comes directly out of the wp-config.php
file which is a bit more safe.
add a comment
|
I'm glad that you got it! This is the best way to learn things. To help you a bit, I'll show you the correct way to do this in WordPress (PHP):
<?php
//DB
global $wpdb;
//Get results from the database
$results = $wpdb->get_results( "SELECT O.order_item_id, O.order_item_name, MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class', MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees' FROM wp_woocommerce_order_items O INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id WHERE O.order_item_name='Smiths Night School' GROUP BY O.order_item_id, O.order_item_name" );
foreach ( $results as $result )
echo $result->your_field_from_the_table;
WordPress defines a class called wpdb
, which contains a set of functions used to interact with a database. It's a good way using this class, because it's simple and save.
You also don't need to define your password
and user
of the database within any PHP file (What you need to do if you use the PHP database functionality). If you use wpdb
, this information comes directly out of the wp-config.php
file which is a bit more safe.
add a comment
|
I'm glad that you got it! This is the best way to learn things. To help you a bit, I'll show you the correct way to do this in WordPress (PHP):
<?php
//DB
global $wpdb;
//Get results from the database
$results = $wpdb->get_results( "SELECT O.order_item_id, O.order_item_name, MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class', MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees' FROM wp_woocommerce_order_items O INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id WHERE O.order_item_name='Smiths Night School' GROUP BY O.order_item_id, O.order_item_name" );
foreach ( $results as $result )
echo $result->your_field_from_the_table;
WordPress defines a class called wpdb
, which contains a set of functions used to interact with a database. It's a good way using this class, because it's simple and save.
You also don't need to define your password
and user
of the database within any PHP file (What you need to do if you use the PHP database functionality). If you use wpdb
, this information comes directly out of the wp-config.php
file which is a bit more safe.
I'm glad that you got it! This is the best way to learn things. To help you a bit, I'll show you the correct way to do this in WordPress (PHP):
<?php
//DB
global $wpdb;
//Get results from the database
$results = $wpdb->get_results( "SELECT O.order_item_id, O.order_item_name, MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class', MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees' FROM wp_woocommerce_order_items O INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id WHERE O.order_item_name='Smiths Night School' GROUP BY O.order_item_id, O.order_item_name" );
foreach ( $results as $result )
echo $result->your_field_from_the_table;
WordPress defines a class called wpdb
, which contains a set of functions used to interact with a database. It's a good way using this class, because it's simple and save.
You also don't need to define your password
and user
of the database within any PHP file (What you need to do if you use the PHP database functionality). If you use wpdb
, this information comes directly out of the wp-config.php
file which is a bit more safe.
answered Mar 28 at 12:32
Mr. JoMr. Jo
1,2924 silver badges24 bronze badges
1,2924 silver badges24 bronze badges
add a comment
|
add a comment
|
The following code works well. This query returns class and fee-type information for every order_item_name of "Smiths Night School".
SELECT
O.order_item_id, O.order_item_name,
MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class',
MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees'
FROM wp_woocommerce_order_items O
INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id
WHERE O.order_item_name='Smiths Night School'
GROUP BY O.order_item_id, O.order_item_name
If you want to do this now in WordPress, you can check my answer.
– Mr. Jo
Mar 28 at 12:26
add a comment
|
The following code works well. This query returns class and fee-type information for every order_item_name of "Smiths Night School".
SELECT
O.order_item_id, O.order_item_name,
MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class',
MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees'
FROM wp_woocommerce_order_items O
INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id
WHERE O.order_item_name='Smiths Night School'
GROUP BY O.order_item_id, O.order_item_name
If you want to do this now in WordPress, you can check my answer.
– Mr. Jo
Mar 28 at 12:26
add a comment
|
The following code works well. This query returns class and fee-type information for every order_item_name of "Smiths Night School".
SELECT
O.order_item_id, O.order_item_name,
MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class',
MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees'
FROM wp_woocommerce_order_items O
INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id
WHERE O.order_item_name='Smiths Night School'
GROUP BY O.order_item_id, O.order_item_name
The following code works well. This query returns class and fee-type information for every order_item_name of "Smiths Night School".
SELECT
O.order_item_id, O.order_item_name,
MAX(CASE WHEN OIM.meta_key = 'class' THEN OIM.meta_value END) AS 'class',
MAX(CASE WHEN OIM.meta_key = 'fee-type' THEN OIM.meta_value END) AS 'fees'
FROM wp_woocommerce_order_items O
INNER JOIN wp_woocommerce_order_itemmeta OIM ON O.order_item_id = OIM.order_item_id
WHERE O.order_item_name='Smiths Night School'
GROUP BY O.order_item_id, O.order_item_name
answered Mar 28 at 10:51
John SmithJohn Smith
11610 bronze badges
11610 bronze badges
If you want to do this now in WordPress, you can check my answer.
– Mr. Jo
Mar 28 at 12:26
add a comment
|
If you want to do this now in WordPress, you can check my answer.
– Mr. Jo
Mar 28 at 12:26
If you want to do this now in WordPress, you can check my answer.
– Mr. Jo
Mar 28 at 12:26
If you want to do this now in WordPress, you can check my answer.
– Mr. Jo
Mar 28 at 12:26
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394547%2fhow-do-you-work-with-database-meta-key-and-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There is a cool search console named Google which returns you an array with > 440.000 entries when you search for this topic. ;)
– Mr. Jo
Mar 28 at 10:11
Thanks for that incredibly unhelpful response. I have Googled the topic extensively and asked for help on forums without any answer.
– John Smith
Mar 28 at 10:17
Have you checked WooCommerce's documentation already? There must be a function for this already.
– cabrerahector
Mar 28 at 10:21
1
Because these are basics of WordPress development mate. For example when I search for: WordPress select from database: codex.wordpress.org/Class_Reference/wpdb. So this is the basic thing. WooCommerce implemented this for you so you can use functions to get order item values by keys. (see the documentation or search on SO): stackoverflow.com/questions/39401393/…
– Mr. Jo
Mar 28 at 10:23
1
Possible duplicate of How to get WooCommerce order details
– Mr. Jo
Mar 28 at 10:24