Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-01-23
1
Medium Priority
?
429 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 37

Accepted Solution

by:
Kimputer earned 2000 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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

782 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