Solved

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

Posted on 2015-01-23
1
414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 36

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.
The viewer will learn how to count occurrences of each item in an array.
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 …

635 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