I have to change the word $15 in all meta_value except 1 meta_key name : pricing_tier
UPDATE postmeta SET meta_value = REPLACE(meta_value, '$15', '$10');
I couldn't find anyway to exclude pricing_tier ACF field from the query.
any help will be appreciated.
Related
I'm having troubles with this command
UPDATE wp_usermeta
SET meta_value = REPLACE(
meta_value,
'a:1:{s:6:"seller";b:1;}',
'a:1:{s:11:"wcfm_vendor";b:1;}')
WHERE meta_key LIKE 'wp_capabilities'
I get a syntax error near ''a:1:{s:6:"seller")' at line 3.
If i run this one ...
UPDATE wp_usermeta
SET meta_value = 'a:1:{s:11:"wcfm_vendor";b:1;}'
WHERE meta_key LIKE 'wp_capabilities' AND meta_value LIKE 'a:1:{s:6:"seller";b:1;}'
I also get the error near ''a:1:{s:11:"wcfm_vendor")' at line 1.
But this one works...
UPDATE wp_usermeta
SET meta_value = REPLACE(
meta_value,
'6:"seller',
'11:"wcfm_vendor')
WHERE meta_key LIKE 'wp_capabilities' AND meta_value LIKE '%"seller"%'
I have a table aus_woocommerce_order_itemmeta with the following schema:
How can I create a query that yields the following logic?
SELECT * FROM aus_woocommerce_order_itemmeta WHERE order_item_id = 660
/* And only from those items, the ones with order_item_id = 660
SELECT the rows that meet any of the following conditions: */
meta_key LIKE "%bebida caliente%"
meta_key LIKE "%elige%"
meta_key LIKE "%agregar%";
This is my current query:
SELECT order_item_id, meta_key, meta_value
FROM aus_woocommerce_order_itemmeta WHERE order_item_id = 660
AND meta_key LIKE "%bebida caliente%"
OR meta_key LIKE "%elige%"
OR meta_key LIKE "%agregar%";
But obviously, the OR statements are on the same level as the first WHERE condition, so it's returning everything, regardless of its order_item_id.
Just wrap the or statement in a parenthesis like this.
SELECT order_item_id, meta_key, meta_value
FROM aus_woocommerce_order_itemmeta WHERE order_item_id = 660
AND (meta_key LIKE "%bebida caliente%"
OR meta_key LIKE "%elige%"
OR meta_key LIKE "%agregar%");
I am trying to list all post_id where meta_key = '_length' AND meta_value => 48 however meta_value is LONGTEXT.
I have the first part figured out:
SELECT post_id, meta_key, meta_value
FROM postmeta
WHERE (meta_key = '_length' AND meta_value = '49')
ORDER BY post_id;
I tried using Convert and CAST and keep getting errors. I decided I needed a little help after reading for a few hours.
After more reading I found an answer.
I believe it was just a two part syntax error.
I was trying
SELECT post_id, meta_key, meta_value
FROM postmeta
WHERE (meta_key = '_length' AND (CAST(meta_value AS INT) > 48))
ORDER BY post_id;
However when casting AS I had to switch to UNSIGNED, then I cleaned up the parentheses and the following query works.
SELECT post_id, meta_key, meta_value
FROM postmeta
WHERE (meta_key = '_length' AND CAST(meta_value AS UNSIGNED) > 48)
ORDER BY post_id;
I have a MySQL Wordpress database and I'm dealing with the postmeta table which isn't nicely structure. It has four columns: "meta_id, post_id, meta_key, meta_value". This is the query I am working with:
SELECT DISTINCT *
FROM wp_10_postmeta as pm
JOIN wp_10_posts AS p ON pm.post_id = p.ID
WHERE (meta_key LIKE 'personnel_%_last_name' OR
meta_key LIKE 'personnel_%_first_name' OR
meta_key LIKE 'personnel_%_title' OR
meta_key LIKE 'personnel_%_alias' OR
meta_key LIKE 'webpages_%_title' OR
meta_key LIKE 'webpages_%_alias' OR
meta_key LIKE 'departments_%_name' OR
meta_key LIKE 'departments_%_alias')
AND post_status = 'publish' AND meta_value LIKE '%john%' AND meta_value LIKE '%smith%'
Issue: This query works great if I search for "john" or "Smith" but if I do "John Smith" it return empty. Is there a way to combine "personnel_%_last_name" and "personnel_%_first_name" and then compare?
I am guessing that you want to look across multiple fields for the match. Try using a group by for this purpose:
SELECT p.*
FROM wp_10_postmeta as pm JOIN
wp_10_posts AS p
ON pm.post_id = p.ID
WHERE (meta_key LIKE 'personnel_%_last_name' OR
meta_key LIKE 'personnel_%_first_name' OR
meta_key LIKE 'personnel_%_title' OR
meta_key LIKE 'personnel_%_alias' OR
meta_key LIKE 'webpages_%_title' OR
meta_key LIKE 'webpages_%_alias' OR
meta_key LIKE 'departments_%_name' OR
meta_key LIKE 'departments_%_alias')
AND p.post_status = 'publish'
GROUP BY p.id
HAVING SUM(meta_value LIKE '%john%') > 0 AND SUM(meta_value LIKE '%smith%') > 0;
I'm trying to add/update a custom field values for all the post for my wordpress site with the code below ... in phpmysql
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID AS post_id, 'views'
AS meta_key 'RAND(6)*20' AS meta_value
FROM wp_posts WHERE ID NOT IN
(SELECT post_id FROM wp_postmeta WHERE meta_key = 'views')
`` AND post_type = 'post';
But this is not working at all ....
Can somebody help me with this !
Instead of 'RAND(6)*20' AS meta_value, use RAND(6)*20 AS meta_value
Basically remove single quotes.