Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!