Loading 0
Share

My Blog

Scroll Down

Find all woocommerce products that are draft or publish with mysql or php

Find all woocommerce products that are draft or publish with mysql or php

Another useful article for die-hards who work with excel lists, google spreadsheets or third party services etc.

Quickly find your woocommerce products that are in draft (draft, non-public) or publish (published) status. You must have entered product code by SKU before running the following.

In case you wish to do it directly through a mysql database manager with phpmyadmin for example, select the database you want and in the command execution give the following:

For all products in draft status:

SELECT wp_postmeta.meta_value FROM wp_posts
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_postmeta.meta_key = '_sku' AND wp_posts.post_status = 'draft' AND wp_p$
AND wp_postmeta.meta_value <> ''

For all products in publish status:

SELECT wp_postmeta.meta_value FROM wp_posts
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_postmeta.meta_key = '_sku' AND wp_posts.post_status = 'publish' AND wp_p$
AND wp_postmeta.meta_value <> ''

Now if you want this in a php file to be pulled as an html table by some service
eg google spreadsheet, create a new file with the extension .php on your server.

Inside put the following (don't forget to put database details):

For all products in draft status:

<!DOCTYPE html>
<html>
<body>

<?php $servername = "localhost"; $username = "ONOMA_XRHSTH"; $password = "KWDIKOS"; $dbname = "ONOMA_BASHS"; // database creation $conn = new mysqli($servername, $username, $password, $dbname); // database connection check if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT wp_postmeta.meta_value FROM wp_posts
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_postmeta.meta_key = '_sku' AND wp_posts.post_status = 'draft' AND wp_posts.post_type = 'product'
AND wp_postmeta.meta_value <> ''";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// extract data from each line
echo "
<table>";
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>". $row["meta_value"]. "</td>
</tr>

";
}
} else {
echo "0 results";
}
echo "</table>

";

$conn->close();
?>

</body>
</html>

For all products in publish status:

<!DOCTYPE html>
<html>
<body>

<?php $servername = "localhost"; $username = "ONOMA_XRHSTH"; $password = "KWDIKOS"; $dbname = "ONOMA_BASHS"; // database creation $conn = new mysqli($servername, $username, $password, $dbname); // database connection check if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT wp_postmeta.meta_value FROM wp_posts
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_postmeta.meta_key = '_sku' AND wp_posts.post_status = 'publish' AND wp_posts.post_type = 'product'
AND wp_postmeta.meta_value <> ''";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// extract data from each line
echo "
<table>";
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>". $row["meta_value"]. "</td>
</tr>

";
}
} else {
echo "0 results";
}
echo "</table>

";

$conn->close();
?>

</body>
</html>

By Nicolas, enjoy 😉

This post is also available in: Ελληνικά

Leave a Reply

Your email address will not be published. Required fields are marked *

01.

Here you can see all the services I provide

Registration and management of domain names (website address such as www.nicolaslagios.com)

Also management of dns records (e.g. connecting the domain to a specific server, fixing email spam problems, etc.)

Also ssl renewals etc

Installation and management of web & mail server in ubuntu vps with virtualmin, plesk, cpanel

Also studying and fixing server problems.

Necessary condition, the target server meets the conditions

At the moment for new wordpress websites you can choose from ready-made themes and we change the content (no custom changes). You can buy with a fixed price by clicking here!

My team and I undertake any data bridging implementation for Wordpress, Prestashop, Opencart, Joomla platforms.

We can connect data from any source, as long as the structure is stable and there is proper documentation and briefing.

We undertake the creation, regulation and enrichment of pages for social networks: Facebook, Linkedin, Instagram (profile), Twitter (profile), Tiktok (profile).

We also undertake the first boost of your pages for quick results in followers.

We undertake the repair and maintenance of your existing wordpress website.

For more information about the services, you can read the following and return here to schedule a meeting with me: https://maxservices.gr/en/internet-services/website-services-blank/additional-website-services/