Jim R Posted September 4, 2017 Share Posted September 4, 2017 This has probably been about six years ago, and I had a lot of help here with this plugin. I'm looking to use it again for another site. The intent of the plugin was with each new Tag (basketball player names) match the slug in wp_terms with wpSlug in a custom data table (same database), then copy the term_id from wp_terms to wpID in the custom data table. This serves as a trigger. It's no longer working, but it's not triggering any readily visible errors. (I'm pretty sure my method at the time was pretty convoluted. If it helps, right now I just wp_terms table to tell my a_players table a matching slug exists.) // Your custom table name define('S_DB','a_players'); add_action('save_post', '__and_upd_other'); add_action('edit_post', '__and_upd_other'); function __and_upd_other( $post_id ) { global $wpdb; if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; } $post_tag = ($_POST['tax_input']['post_tag']) ? $_POST['tax_input']['post_tag'] : ''; if('' != $post_tag) : $post_tag = explode(',',$post_tag); $ptc = 0; // Build string of OR matches for the query foreach($post_tag as $tag) { $ptc++; if($ptc == 1) { $tt = "terms.name = '$tag'"; } else { $tt .= " OR terms.name = '$tag'"; } } // Get the tag ids and slugs for the saved post $tags = $wpdb->get_results(" SELECT terms.term_id, terms.slug FROM $wpdb->terms as terms JOIN $wpdb->term_taxonomy as tax ON tax.term_id = terms.term_id JOIN $wpdb->term_relationships as rel ON rel.term_taxonomy_id = tax.term_taxonomy_id WHERE rel.object_id = '$post_id' AND tax.taxonomy = 'post_tag' AND $tt ", ARRAY_A); // Create 2 empty strings $mstr = $lstr = ''; // Build a case string for the next query foreach($tags as $t => $tag) { $mstr .= "when '$tag[slug]' then '$tag[term_id]' "; $lstr .= "'$tag[slug]',"; } // Unset unused data unset($tags); // Remove the last comma off the second string $lstr = substr($lstr,0,-1); // Create the a nifty query to do multiple updates in one query $wpdb->query( $wpdb->prepare(" UPDATE ".S_DB." SET ".S_DB.".wpID = case wpSlug $mstr end WHERE ".S_DB.".wpSlug in(%s)"), $lstr); //old line before switching due 3.5 upgrade WHERE ".S_DB.".wpSlug in($lstr)")); endif; return; } Quote Link to comment https://forums.phpfreaks.com/topic/304861-older-wp-plugin-i-created-no-longer-works/ Share on other sites More sharing options...
Jim R Posted September 5, 2017 Author Share Posted September 5, 2017 I may have solved the issue by setting up triggers in my database. Quote Link to comment https://forums.phpfreaks.com/topic/304861-older-wp-plugin-i-created-no-longer-works/#findComment-1550745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.