Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda