0

I have set up 2 custom taxonomies for my posts: verdicts and sponsors.

The problem is that sponsors do not get saved when publishing a post, it can only get saved when I check it in quick edit mode.

The code for my custom taxonomy is pretty basic, as you can see below.

Does anyone have any idea? Thanks!

<?php 
// Register Custom Taxonomy
function custom_sponsors() {

    $labels = array(
        'name'              => _x( 'Sponsors', 'Taxonomy General Name', 'text_domain' ),
        // the rest of labels
    );
    $rewrite = array(
        'slug'              => 'sponsor',
        'with_front'        => true,
        'hierarchical'      => true,
    );
    $args2 = array(
        'labels'            => $labels,
        'hierarchical'      => true,
        'public'            => true,
        'show_ui'           => true,
        'show_admin_column' => true,
        'show_in_nav_menus' => true,
        'show_tagcloud'     => false,
        'query_var'         => 'sponsor',
        'rewrite'           => $rewrite,
    );
    register_taxonomy( 'sponsor', array( 'post' ), $args2 );
}

// Hook into the 'init' action
add_action( 'init', 'custom_sponsors', 0 );
  • The code you've posted does not have anything to do with saving posts. Show us add_action( 'save_post', 'your_function_name' ); part. – Max Yudin Nov 21 at 16:34
  • I have not created one since I am not using custom posts, only custom taxonomies for the native posts ... Was I wrong? Thanks! – Adrian Rafail Nov 22 at 17:16
  • My bad, I was inattentive on post type. I can't reproduce the problem, your code works for me flawlessly. Try the following. Flush rewrite rules (Settings → Permalinks → Save) and see if it helps. If not, change init action priority to something different from 0, let's say 10. – Max Yudin Nov 23 at 8:08
  • Thanks for this but it did not work. I have also tried saving with all of the plugins deactivated. It works fine when checking that taxonomy in quick-edit mode. This is so weird. – Adrian Rafail Nov 23 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.