Improve company productivity with a Business Account.Sign Up

x
?
Solved

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

Posted on 2011-03-22
10
Medium Priority
?
661 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
 
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 1000 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

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.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Laravel is the most sought after web development framework. It comes with ample amount of features that make it easy for developers to work around it. Know about its features in detail.
The viewer will learn how to count occurrences of each item in an array.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

606 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