0

All I want is to set a custom posts taxonomy. Here is the taxonomy "lostitem" I registered for the custom post type "verloren"

function create_taxonomies(){
$labels = array(
    'name' => _x('Lost Items', 'taxonomy general name'),
    ...
);

$args = array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'lost-items'),
);

register_taxonomy('lostitem', array('verloren'), $args);
}add_action('init','create_taxonomies');

Within a form I want to set the posts taxonomy tag (in this example with tag ID 13), but its not working.

// Formular Verloren
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) 
&& $_POST['action'] == "new_post") {

$post_information = array(
'post_type' => 'verloren',
);

$postID = wp_insert_post( $post_information ); //here's the catch

    update_field('field_580b7f49ed5dc', $_POST['mail'], $postID);
    ...
  $tag = array( 13 );
  wp_set_object_terms( $postID, $tag, 'lostitem');



//Redirect to Page
wp_redirect(get_permalink(100)); exit;
}

I tried various options I found here, like registering the taxonomy before the custom post type without success. The taxonomy shows up well in the admin backend and I can also receive the terms it in the forms dropdown. Don`t know where else to investigate. Thanks for help!

  • If 13 is a term ID, it should be passed as an integer, not a string. – Milo Oct 30 '16 at 15:30
  • Thanks, checked the guidelines and made an edit in the code, but still no change. – Rainer Oct 30 '16 at 15:46

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.