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
Solved

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

Posted on 2011-03-22
10
620 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

828 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