Plugin works for default post types, but not for custom
-
I’ve coded a plugin that adds a meta box to the post page. When the post is published, the plugin will generate a random ID for the post, and insert the random ID and the post guid to a custom table in the database. After publishin, or upon editing, the plugin queries the custom table to retrieve the random ID for the post based on the post guid, and prints out the random ID in the meta box.
Everything works great until I try to change the post type in the add_meta_box function from ‘post’ to ‘quilt’. The plugin will generate the random ID and save it and the post guid to the table, but presents this error in the meta box:
Notice: Trying to get property of non-object in /home/qultshow/public_html/wp-content/plugins/randomID/randomID.php on line 126
instead of the random ID. If I use
var_dump( $query ); $wpdb->print_error();
to try to debug, I see:
NULL
WordPress database error: [] SELECT * FROM wp_customtable WHERE qrci_guid = “http://testsite.com/?post_type=quilt&p=213”
If I run the above query in phpmyadmin, a row is returned as expected.
Is there something odd or different about querying the database from a custom post type that I need to know about to make this work?
Thanks for any help!
P.S. This plugin is not for usage by anyone but me on one website where I need this weird functionality. Also, this is a multi-site installation of wordpress if that makes any difference. I can’t use post metadata for this since I need to be able to query this data without querying every postmeta table on the network, so it has to be a custom table in the database.
- The topic ‘Plugin works for default post types, but not for custom’ is closed to new replies.