Quantcast
Channel: Question and Answer » wpdb
Viewing all articles
Browse latest Browse all 44

Cannot access the thumbnails of attachment images… Cannot find the reason

$
0
0

I have a custom form that allows users to make posts and also upload images with it.
The images are saved in wp_posts as post_type = attachment with a guid to show the image.

Now I have created a grid created with php which shows all main pictures of my posts. However, since I call the guid’s of the images it loads very slow when the pictures are large.

I know that there is some smaller thumbnail that should get saved with each image upload, but I cannot find these files in the database.

I tried showing them with all of the following ways:

//test with ID of the post:
get_the_post_thumbnail('17547');
get_the_post_thumbnail(17547, 'thumbnail');
get_the_post_thumbnail(17547, 'medium');

//test with ID of the attachment:
wp_get_attachment_image(17548, 'medium' );
wp_get_attachment_image_src(17548, 'medium' );

The two different numbers are because i tried the post ID and the attachement ID. But all of the above functions don’t show me anything in the DOM…

I think that maybe the way I save the pictures doesn’t allows me to use this function. But I don’t know what I’m doing wrong! Does anyone know where I can look or how I can show these thumbnails?

This is how my photo grid is made:
 First I get a list of ID’s based on what the user searches:

$allluca01 = $wpdb->get_results("
    SELECT wpp.ID, post_title
    FROM wp_posts AS wpp
    WHERE post_type = 'post' 
    ".$plus_other_search_conditions."
    GROUP BY wpp.ID
");

 Then I get the guid of the image. I have the attachment id saved as metavalue to a metakey called image01 (linked to post_id).

foreach($sqlsearchquery as $results){
        $resultid = $results->ID;
        $getpicture = $wpdb->get_results("
            SELECT guid AS pic 
            FROM wp_posts
            LEFT JOIN wp_postmeta ON ID = meta_value
            WHERE post_id = '$resultid' AND meta_key = 'item_image01'
        ");

            <div class="grid_item_img" style="background-image:url('<? echo $getpicture[0]->pic; ?>')">

As you can see I attain the guid and then I use it in my grid. I just want to obtain a guid of a smaller size of my media so I can have the grid load faster. Does anyone know how to do that?


Viewing all articles
Browse latest Browse all 44

Trending Articles