WPDB issue with get_var
-
currently modifying a plugin, it’s an autopost plugin that makes a post everytime you upload an image. added functionality to add to a custom post type which is fine.
trying to link it up with another plugin. namely real media library.
they use a cool system for folders in the media library. i’ve managed to root around in the mysql and found where the terms are kept for linking an attachment number to a folderid (fid) and to a name of the category/folder it was store in.in the plugin i read that you need to declare the wpdb as global and added error showing.
it gets a variable “attachdb” from the plugin function which contains an id number
in the same function it goes to the db and picks out from the real media library the fid with the matching attachement id so in my case it would be one folder/one id
then it passes that fid to get the slug in another query before adding it to the custom post type’s category
here is a snippet of the code for wpdbglobal $wpdb; $wpdb->show_errors(); $slugid = $wpdb->get_var( $wpdb->prepare(" SELECT fid FROM wpa_realmedialibrary_posts WHERE attachment = %d ", $attachdb ) ); $name = $wpdb->get_var( $wpdb->prepare(" SELECT slug FROM wpa_realmedialibrary WHERE id = %d ", $slugid ) );this following bit works fine. adding the slug to the custom post type.
$docterm = get_term_by('slug', $name, 'document_category'); wp_set_post_terms( $post_id, $docterm->term_id, 'document_category' );when using it the $slugid comes out null/not able to see anything.
am i doing something drastically wrong. im assuming its to do with wpdb in the plugin or my poor attempts at coding. but would love if someone has some ideas. not a dev by trade so go easy on me.
The topic ‘WPDB issue with get_var’ is closed to new replies.