Last active
July 30, 2021 07:52
-
-
Save polevaultweb/a3e8b73caa9d1c1c700fb4c3a25f4dd5 to your computer and use it in GitHub Desktop.
Select a value from a serialized array using the array key in MySQL https://polevaultweb.com/2020/02/selecting-data-serialized-array-mysql/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# replace 'file' with the array key you want to extract | |
SELECT | |
SUBSTRING_INDEX( | |
SUBSTRING_INDEX( | |
SUBSTRING(pm.meta_value, ( INSTR( pm.meta_value, CONCAT( 'file', '";' ) ) + CHAR_LENGTH( 'file') + 1 ) ), | |
'"', 2 ), | |
'"', -1 ) as attachment_file | |
FROM wp_posts p | |
INNER JOIN wp_postmeta pm | |
ON p.ID = pm.post_id | |
AND pm.meta_key = '_wp_attachment_metadata' | |
WHERE post_type = 'attachment' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment