Get 2 meta values from meta key column

Not tested 100% but this might work: SELECT a.post_title, m1.meta_value AS SKU, m2.meta_value AS PRICE FROM wp_posts a LEFT JOIN wp_postmeta m1 ON a.ID = m1.post_id LEFT JOIN wp_postmeta m2 ON a.ID = m2.post_id WHERE a.post_type=”product” AND m1.meta_key=’_sku’ AND m2.meta_key=’_price’ Note that _price field corresponds to the “sale price” (if existing) so you may grab … Read more

What is the correct way to search 3 custom fields only in WordPress?

Are you using Advanced Custom Fields?(ACF?). Relevanssi is a really good plugin which increases the scope of the core WordPress search. Here’s the link: https://wordpress.org/plugins/relevanssi/ It allows users to search for posts via ACF fields attached to them. Once you install the plugin, you can use the following code in your functions.php file to instruct … Read more

How can I find user role in Mysql?

I’ve decided to use plain Key according to @TomJNowell ‘s comments. If I would like to search a key in serialized data, I would get those serialized array from DB and use maybe_unserialize() in PHP OR use WP_User_Query in PHP. Thank you @TomJNowell

Find locations of all featured images of draft posts via SQL

Alright this worked for me: First run the bellow script to generate the file locations of all files used for draft posts. SELECT voybp_posts.guid FROM voybp_posts WHERE voybp_posts.ID IN (SELECT voybp_postmeta.meta_value FROM voybp_postmeta WHERE voybp_postmeta.post_id IN ( SELECT voybp_posts.ID FROM voybp_posts WHERE voybp_posts.post_status=”draft”) AND voybp_postmeta.meta_key=”_thumbnail_id”) Export this as a CSV file and save it to … Read more

Store GravityForm data in phpmyadmin (mysql)

You can use something like below. Basically after form submission we get the data $entry extract the values we want (in the example $val1, $val2, $val3) then insert that data into the custom table with $wpdb: add_action(‘gform_after_submission’, ‘save_to_my_custom_table’, 10, 2); function save_to_my_custom_table($entry, $form) { global $wpdb; // update for your tablename (this assumes the table … Read more