[Plugin: Custom Content Type Manager] SQL error after uploading then inserting using Media field
-
I was testing out the various custom field types and noticed an issue with the Image and Media field types. For example, I added a Media field to a new custom content type. When I tested creating a new post using this content type, I got an SQL error shown on screen after uploading the media file (a PDF) and then clicking on the “Insert into Post” button. What happens is that the upload dialog closes and then directly below the “Choose Media” and “Upload” buttons I see the following error:
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”http://localhost:8444/wordpress/?attachment_id=105′ ) GROUP BY wp_posts.ID ORDE’ at line 1]
SELECT wp_posts.* , parent.ID as ‘parent_ID’ , parent.post_title as ‘parent_title’ , parent.post_excerpt as ‘parent_excerpt’ , author.display_name as ‘author’ , thumbnail.ID as ‘thumbnail_id’ , thumbnail.guid as ‘thumbnail_src’ , metatable.metadata FROM wp_posts LEFT JOIN wp_posts parent ON wp_posts.post_parent=parent.ID LEFT JOIN wp_users author ON wp_posts.post_author=author.ID LEFT JOIN wp_term_relationships ON wp_posts.ID=wp_term_relationships.object_id LEFT JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id=wp_term_relationships.term_taxonomy_id LEFT JOIN wp_terms ON wp_terms.term_id=wp_term_taxonomy.term_id LEFT JOIN wp_postmeta thumb_join ON wp_posts.ID=thumb_join.post_id AND thumb_join.meta_key=’_thumbnail_id’ LEFT JOIN wp_posts thumbnail ON thumbnail.ID=thumb_join.meta_value LEFT JOIN wp_postmeta ON wp_posts.ID=wp_postmeta.post_id LEFT JOIN ( SELECT wp_postmeta.post_id, CONCAT( GROUP_CONCAT( CONCAT(wp_postmeta.meta_key,’::::’, wp_postmeta.meta_value) SEPARATOR ‘,,,,’), ‘$$$$’) as metadata FROM wp_postmeta WHERE wp_postmeta.meta_key NOT LIKE ‘\_%’ GROUP BY wp_postmeta.post_id ) metatable ON wp_posts.ID=metatable.post_id WHERE ( 1 AND wp_posts.guid ‘http://localhost:8444/wordpress/?attachment_id=105’ ) GROUP BY wp_posts.ID ORDER BY wp_posts.IDIt seems that the issue is the final WHERE clause, i.e.:
WHERE ( 1 AND wp_posts.guid 'http://localhost:8444/wordpress/?attachment_id=105' )
This obviously isn’t valid SQL since there is no comparison operator between wp_posts.guid and the url. I have never touched any php before, but I was looking through the php code for this plugin and I think I’ve found the line that generates that SQL for that WHERE clause. It is within the _get_sql function and looks like this:
$hash['direct_filter'] .= $this->_sql_filter($wpdb->posts, $c, $this->operators[$c], $this->$c);
I added a bit of logging below this and apparently $c has a value of ‘guid’ and I’m assuming that it doesn’t have an operator defined within operators. I noticed that the line directly above this line of code is commented out, so I tried uncommenting that line and commenting the one below it and now the SQL doesn’t break. This is obviously because the ‘=’ operator is hardcoded.
The only problem is that the generated SQL doesn’t return anything. There are no posts in my database with a guid value of ‘http://localhost:8444/wordpress/?attachment_id=105’ and in fact this URL doesn’t reference anything on my site.
But I do have a wp_posts row with an ID value of 105 with a guid that is of this form:
http://localhost:8444/wordpress/wp-content/uploads/2012/01/FilenameHere.pdf
This makes me think that my attachment guid format is not compatible with the plugin.
I’ll admit that I’m not up to speed with everything WordPress so I might be missing something obvious here.
These are the versions I am using:
Plugin Version: 0.9.5.6-pl
WordPress Version: 3.3
PHP Version: 5.2.17
MySQL Version: 5.5.8
Server OS: WINNThttp://wordpress.org/extend/plugins/custom-content-type-manager/
- The topic ‘[Plugin: Custom Content Type Manager] SQL error after uploading then inserting using Media field’ is closed to new replies.