Yes, a database query is possible with WordPress:
function is_image_in_network( $image_name )
{
global $wpdb;
$image = "uploads/2012/01/{$image_name}";
$value="%".like_escape( $image ).'%';
$blog_id = get_current_blog_id();
$wpdb->set_blog_id( $blog_id );
$image = $wpdb->get_var(
$wpdb->prepare(
"SELECT ID FROM {$wpdb->posts}
WHERE post_status="publish"
AND post_content LIKE '%s'"
, $value
)
);
return is_null( $image ) ? false : true;
}
You can use it as function in your templates. Just add the image name, you’re searching for as argument. The new “Template Tag” works like every default WP “Conditional Tag”.
Is that image.php
in the Question a typo?
I’m leaving the search string %uploads/2012/01/an_image%
without an extension so it can catch all the images (original and thumbnails).
Documentation: Class_Reference/wpdb.
Related Posts:
- How to create Sub Sub domain Multi User blogs?
- Is it best to avoid using $wpdb for security issues?
- How do I display offsite database info on my wordpress site?
- Timthumb.php image gallery not working on Multisite WordPress
- Multiple WordPress sites with different theme and plugin sharing the same content
- Host does not allow remote connection, so how do I transfer data to my WordPress site?
- Trying to post information from a remote database to wordpress page
- Echo URL of large version of Featured Image
- Adding Custom Forms
- How do I let users upload files to a chosen location?
- Adding hreflang tags automatically in WordPress subdirectory multisite
- SQL QUERY – Select a value directly from the database
- Change the URL of an image from wp_get_attachment_image_src except in the frontpage
- Get different images for mobile and desktop with php, advanced custom fields without using js and ajax
- How to get specific image in media library with php
- How to get the POST TITLE using the POST ID?
- Why is the post meta[] empty when I make a call to the wordpress rest api?
- hover image appears below placeholder instead of overlayed
- Is it necessary to sanitize wp_set_password user input?
- Any possible way to make $wpdb->get_results() return anything else than array?
- database interactions using OOP
- How to add values to media “whitelist_options” in wp-admin/options.php template?
- WordPress Scheduled Event Request Blocking
- Transferring working local PHP site to wordpress – with database (MySQL)
- add_image_size for header_image
- Add custom url to featured image
- Accessing the database from a plugin outside of action hooks
- Get image’s size name from it’s dimension
- Cannot display or echo alt text on featured image
- Trying to establish connection to External Database
- Recent posts with featured image or fallback image with permalink
- Create WP_Query to search for posts by their categories or their parent/child categories
- Getting id of poll from WP database
- Best practice for migration friendly images in posts/pages?
- Storing Array from returned database query and using the array in a new query
- How to insert a single row to WP database table?
- Set the background to a default image if there isn’t a specified “featured image”
- How to change home or site url using action hooks or filter?
- WordPress not reflecting changed of the database
- Mass update excerpt
- $wpdb->update with multiple parameters gives error
- How to save checkbox values for logged in users?
- How to control WordPress image metadata (using Imagick)?
- wp search-replace on database returns PHP fatal error: Array and string offset access syntax with curly braces is no longer supported
- wordpress media library new uploads don’t write to database
- Get the post ID and display the images
- Responsive Header for Phone
- How does WordPress know wich language is chosen when there is a database connection error
- Reprinting tags with all attributes
- WordPress returning 404 for multisite pages
- How can I save unique user data on my site? [closed]
- How to call plugin function per site in a multisite?
- How to get next image with this code from same post?
- WordPress returns “The link you followed has expired” error page whenever I add a new site, add a user etc
- Unread Repeater field IMG alt not working
- Is it possible to create a wordpress database with php code?
- Update results, Before deleting the related category [closed]
- Can’t upload image using media_sideload_image
- Store a default value for a transient on plugin activation
- Upload multiple images to a Woocomerce product
- How WordPress reacts to a lack of memory of the server [closed]
- How to use thumbnail size of image if I’m only using src to get image
- Split reads to a different connection string
- custom user role wordpress – grant guest access to edit.php without insert/update/delete
- Execute long and heavy processes
- Dynamic content in template
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- Accessing an image folder inside public web directory
- get_children displaying images removed from the page
- Why is image hard cropping for one image using add_image_size not working?
- database sent to a JSON file
- Enable custom logo upload if logo is not in header
- NGINX rewrite rules for multisite
- Make a list of sites for each user in WPMU – switch_to_blog (display in SITE_ID: 1)
- Why my image upload button is not working in wordpress widget area?
- inserting a post from an extern php file but post content doesn’t show on wp site
- Scrape external webpage for first image and add it to new post
- How to make own crop image function for WordPress plugin
- “imagejpeg” function is not working in wordpress
- Display image from an external rss feed on wordpress without plugins
- WP & Server Speed [Teacher Question]
- Using custom tables for old posts
- Databases – Submitting data from inputs to database [closed]
- db converts decimal number wrong
- Redirect to another page using contact form 7? [closed]
- Not connecting to database in file with multiple MySQL connections
- WordPress automatically adds links to uploaded images
- WordPress function when file is uploaded, deleted or edited
- Moving code from theme header to functions.php
- Filtering a Database Query
- Download images from media library to computer in BULK?
- Three Questions with Twenty Eleven theme
- Display Data in Table from External Database in WP using Shortcodes
- Count posts on multisite with blog id
- How can I import an excel column into wordpress database?
- Blob file download problem
- How to loop through all the attached images in a post, and get their url one by one
- WordPress Block developer from exporting Database via PHP
- How to retrieve the data from the sever and displaying it in a page?
- Which function crops images in wordpress?