Solved

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

Posted on 2015-01-23
1
411 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 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

752 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