Solved

How can I query a specific Wordpress Featured Image Size with SQL

Posted on 2015-01-23
1
391 Views
Last Modified: 2015-02-13
I guess my theme creates multiple featured image sizes.  I would like to query the "medium" image size from the meta_value in the post_meta table.

a:6:{s:5:"width";i:900;s:6:"height";i:500;s:4:"file";s:49:"2015/01/blog_lego_smaller_boxes_green_profits.jpg";s:5:"sizes";a:5:{s:9:"thumbnail";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:28:"Reduced by 6.7% (599 B)";}s:6:"medium";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-300x167.jpg";s:5:"width";i:300;s:6:"height";i:167;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:29:"Reduced by 7.5% (1.3 KB)";}s:14:"shop_thumbnail";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-200x200.jpg";s:5:"width";i:200;s:6:"height";i:200;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:28:"Reduced by 6.6% (897 B)";}s:12:"shop_catalog";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-400x400.jpg";s:5:"width";i:400;s:6:"height";i:400;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:29:"Reduced by 6.8% (2.3 KB)";}s:11:"shop_single";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-600x500.jpg";s:5:"width";i:600;s:6:"height";i:500;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:29:"Reduced by 7.1% (4.1 KB)";}}s:10:"image_meta";a:11:{s:8:"aperture";i:0;s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";i:0;s:9:"copyright";s:0:"";s:12:"focal_length";i:0;s:3:"iso";i:0;s:13:"shutter_speed";i:0;s:5:"title";s:0:"";s:11:"orientation";i:0;}s:10:"wp_smushit";s:27:"Reduced by 1.8% (1 KB)";}

Open in new window


I am looking to grab this:

s:6:"medium";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-300x167.jpg"

Open in new window


in the end i will just get this

blog_lego_smaller_boxes_green_profits-300x167.jpg

Open in new window



Is there a way I can query the db to return that image name?
0
Comment
Question by:theideabulb
1 Comment
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
ID: 40566562
Can you just query the usual (get the whole string)?

Then put it through here (of course, replace $test with the result string from the database):


<?php

$test =  'a:6:{s:5:"width";i:900;s:6:"height";i:500;s:4:"file";s:49:"2015/01/blog_lego_smaller_boxes_green_profits.jpg";s:5:"sizes";a:5:{s:9:"thumbnail";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:28:"Reduced by 6.7% (599&nbsp;B)";}s:6:"medium";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-300x167.jpg";s:5:"width";i:300;s:6:"height";i:167;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:29:"Reduced by 7.5% (1.3&nbsp;KB)";}s:14:"shop_thumbnail";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-200x200.jpg";s:5:"width";i:200;s:6:"height";i:200;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:28:"Reduced by 6.6% (897&nbsp;B)";}s:12:"shop_catalog";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-400x400.jpg";s:5:"width";i:400;s:6:"height";i:400;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:29:"Reduced by 6.8% (2.3&nbsp;KB)";}s:11:"shop_single";a:5:{s:4:"file";s:49:"blog_lego_smaller_boxes_green_profits-600x500.jpg";s:5:"width";i:600;s:6:"height";i:500;s:9:"mime-type";s:10:"image/jpeg";s:10:"wp_smushit";s:29:"Reduced by 7.1% (4.1&nbsp;KB)";}}s:10:"image_meta";a:11:{s:8:"aperture";i:0;s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";i:0;s:9:"copyright";s:0:"";s:12:"focal_length";i:0;s:3:"iso";i:0;s:13:"shutter_speed";i:0;s:5:"title";s:0:"";s:11:"orientation";i:0;}s:10:"wp_smushit";s:27:"Reduced by 1.8% (1&nbsp;KB)";}';

$pattern = "#\"(.*?)\"#";
preg_match_all($pattern, $test, $matches);

$key = array_search('medium', $matches[1]);

print_r($matches[1][$key+2]);

?>

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now