Solved

Wordpress get_results returning different results to MySQL direct query? or TimThumb.php acting up?

Posted on 2011-03-22
10
613 Views
Last Modified: 2012-05-11
Hi Experts,

I have a wordpress site that uses a theme called "FotoFolio" from this page

I have made a couple of adjustments to the code, but nothing major, and I am having some major issues with caching or something.
You can see on this page http://shoelacethefilm.com/?p=248 that there is no image loading
http://www.webpagescreenshot.info/img/712808-323201160418AM

The issue is in the HTML generated by the attached PHP file, basically the GUID is not appearing for that particular post, although when I try the query to the Db directly, it works fine - go figure?

So on line 20 of this file single.php is where it should be outputting the HTML src of the guid, but is failing :(.

Thoughts?

Thanks in Advance.
C
0
Comment
Question by:Craig Lambie
  • 5
  • 5
10 Comments
 
LVL 7

Expert Comment

by:Swafnil
ID: 35196805
Could you change line 9-14 with the following lines of code and see what you get?

$sql= "SELECT guid FROM $wpdb->posts WHERE post_parent = '$post->ID' "
	."AND post_type = 'attachment' ORDER BY `post_date` ASC LIMIT 0,1"

$first_image = $wpdb->get_results($sql);
print 'Called statement: '.$sql.'<br />';

Open in new window


If you don't get an output after changing the file it's definitily related to caching, otherwise copy the displayed query and see if there's an error somewhere. HTH!
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 35204100
I changed the line, but put "echo" in place of "print" (Line 5 of attached code)

Result: Called statement: SELECT guid FROM shoe_posts WHERE post_parent = '248' AND post_type = 'attachment' ORDER BY `post_date` ASC LIMIT 0,1

I then ran this against the Database and noted that no records where returned = this is a result.

So the reason this is happening is that when an Image is loaded into this page it is not making a wp_posts record of type "attachment" which it apparently should, and did with other pages.

Thoughts?
0
 
LVL 7

Expert Comment

by:Swafnil
ID: 35204809
Good morning,

have you checked if post 248 has attachments? The above statement shows that no attachments have been foun, so I would take a second look at this specific post.
I don't use Wordpress, so I am not sure if the post_type "attachment" is correct, what does:
SELECT guid FROM shoe_posts WHERE post_parent = '248' ORDER BY `post_date` ASC

Open in new window

display as result?
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 35204832
Hi Swafnil,
Yes - this seems to be the issue.  My issue is that it is not creating this record in the Db, If you don't use Wordpress, you will probably struggle to explain it, as I don't know how the record gets there myself... let alone why it isn't being put there for this particular page.

Thanks, but I think another expert with Wordpress experience will have to take this one.
0
 
LVL 7

Expert Comment

by:Swafnil
ID: 35205261
I've worked with Wordpress before, so we'll find a way to fix this problem.

Are you getting any error messages when you attach the image to the post? You are using the attachment function to add the image, you are not simply inserting it into the post's body, right? Does the attachment show up in WP administration?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:Craig Lambie
ID: 35212440
I thought that posting it into the body of the Page would activate this "attachment" type posting, or at least it has in other pages.
I haven't had to specifically "attach" something to a page before, what exactly do you mean by that?
0
 
LVL 7

Expert Comment

by:Swafnil
ID: 35213570
When you take a look at your post in the WP administration, is the image you attached visible inside the post? If you add an image to the post, you also need to insert it into the post (button "Insert into post", that's one mistake I made when I last used the upload function inside Wordpress). Could you open a MySQL console and execute:

select id, post_title, post_type, post_parent from wp_posts;

Open in new window


See, if the image you specified is shown somewhere in the result and what is set as post_parent.
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 35214001
I am definitely pressing "insert into post"
Please find the SQL output attached. shoe-posts.csv
0
 
LVL 7

Accepted Solution

by:
Swafnil earned 250 total points
ID: 35214308
Apparently WP did not create a new post for the attachment and therefor did not attach it to post "Scene 7.1 the chance". Have you tried to delete the scene from the Media Library, is it even listed on the Media Library overview page? The last added media added has been "come on 19x", this is not the attachment you are trying to attach to the post or is it? Could it be that you have run out of disk space? Sorry it's taking a while but this seems to be a quite tricky problem ...
0
 
LVL 1

Author Closing Comment

by:Craig Lambie
ID: 35225849
That did it.
I removed it from the Media Library and deleted the post, then added it again, and re did the post.

Thanks for your help, not sure what was going on.

I had some issues in when I was trying to repost, so I ended up having to use Firefox to repost, not sure if this is related, but could be relevant to future people with this issue.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now