Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
wp_set_object_terms not working with custom taxonomy and custom post types
$post_type = 'machine';
$title     = $_POST['name'];
$new_post = array(
'post_title'    => $title,
'post_status'   => 'publish',          
'post_type'     => $post_type,
);
$pid = wp_insert_post($new_post);
$category_id = trim($_POST['category']);
$taxonomy = 'machine_categories';
wp_set_object_terms( $pid, (int)$category_id, $taxonomy, true );

Here i create a new post type machine and new taxonomy machine_categories A new custom form created in the front end

<div class="form-group">
    <input type="text" class="form-input" name="name" id="name" placeholder="Post Title" />
</div>
<div class="form-group">
    <label>Post Category</label>
    <select class="form-input" name="category" id="category">
        <option>--Select--</option>
        <?php 
        $terms=g et_terms( array( 'taxonomy'=>'machine_categories', 'hide_empty' => false, ) ); 
        if ( ! empty( $terms ) && is_array( $terms ) ) 
            { 
                foreach ( $terms as $term ) {
        ?>
        <option value="<?php echo $term->term_id; ?>"><?php echo $term->name; ?></option>
        <?php 
            } 
        } 
        ?>
    </select>
</div>

Here is the dropdown code in the frontend, when i submit the post there is an error shows Invalid Taxonomy This taxonomy and post type created using Custom post type ui plugin.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda