ash-ic
Forum Replies Created
-
Oh thanks for that! Hmmm :O( I definitely havent had any emails through (not even in spam), can you try and send it again please. I will email your support email address now so you can just copy and paste into a reply.
Thanks
I managed to output some of the code from your methods and found that the [manufacturer] part of the permalink updates before you get $post_after and $post_before in your post_updated hook. I use the ACF plugin to set the manufacturer/brand of my watch posts so I have managed to successfully detect when the manufacturer(also called brand) changes on save with the following code:
// Check if the watch brand changes on update function my_acf_save_post_watch( $post_id ) { // todo: add check to only run on update $goto_brand = get_post($_POST['acf']['field_55770017d9b58']); $acf_brand_term_id = get_field('brand_tax_term_id', $goto_brand->ID); $manuf_terms= get_the_terms( $post_id, 'manufacturer' ); $current_term_id= $manuf_terms[0]->term_id; if($acf_brand_term_id != $current_term_id){ //echo 'Brand changed from '.$manuf_terms[0]->name.' to '.$goto_brand->post_title; //exit(); } } add_action('acf/save_post', 'my_acf_save_post_watch', 1);The problem is that the manufacturer taxonomy term has already updated before your code runs on the post_updated action. So the acf/save_post and actually the regular wordpress save_post actions display the manufacturer term BEFORE it gets changed.
This may be a useful addition to your plugin to detect whether a taxonomy (and therefore also potentially a permalink prefix) has also changed instead of just using the post_updated $post_before and $post_after, though it may be something that the admin would enable on a per site basis as most people won’t need it.
So this leaves me with the original question as to how do i use the methods of your plugin to add a new redirect which also handles duplicates and avoid infinite redirect loops. I could set a session and modify your method to check for it and trigger the redirect creation along with your before != after condition but it will be lost on plugin update.
Is there any way you could set a hook/function up in the same place that the before/after gets matched where you can send a custom before (eg the one i can generate from my acf action) for it to match. Even if I can just send the part of the url before the title slug that would work.
Its confusing my head trying to figure this all out as I’m still learning WordPress, but this is nearly doing exactly what i want it to, and i really think this would be a good addition to your plugin.
Looking forward to your reply,
Ash
Forum: Plugins
In reply to: [CPT-onomies: Using Custom Post Types as Taxonomies] Possible plugin conflictOk so as I have only just installed cpt-onomies it isn’t tied in to my site at all. I have gotten around this by making a regular old custom taxonomy and writing a script to add post titles as terms to this taxonomy whenever they are created/updated. Its a little crude and not as full featured as cpt-onomies but it works for my purposes so thought I would share it here.
function icam_mirror_cpt_to_taxonomy( $postid ) { // change this to the taxonomy you want to add to $taxonomy = 'watch_brand'; // get all of the details of the post that is currently being edited $post = get_post($postid); // don't save this post as a taxonomy term if auto draft, eg. when creating a new post if($post->post_status == 'auto-draft') return; $term = get_term_by('slug', $post->post_name, $taxonomy); // try to get this new term from the taxonomy if ( empty($term) ) { // and if it doesn't exist // and finally add the currently edited post title as a term in the taxonomy $add = wp_insert_term( $post->post_title, 'watch_brand', array('slug'=> $post->post_name) ); if ( is_array($add) && isset($add['term_id']) ) { wp_set_object_terms($postid, $add['term_id'], 'watch_brand', true ); } } } // add the action, change brand to your cpt add_action('save_post_brand', 'icam_mirror_cpt_to_taxonomy');Forum: Plugins
In reply to: [CPT-onomies: Using Custom Post Types as Taxonomies] Possible plugin conflictYes I have this problem as well, and you don’t actually need to be using any of the CPT onomies with the media library, just having it installed causes the error in list view.
If this is fixed everything will be perfect in my world as they are two really great plugins!