I have a cpt with front-end creation on the front page.
Using a 2013 child theme.
Using wp_dropdown_categories to output the cats and the output is correct:
<select name="cat" id="cat" class="postform">
<option value="-1">Select Category</option>
<option class="level-0" value="1">Uncategorized</option>
<option class="level-0" value="4">National</option>
etc.
After inserting the post, I do this:
$selected_cat = array( $_POST['cat'] );
wp_set_post_terms($post_id, $selected_cat, 'category');
Everything works except when I submit I end up on the 'Nothing Found' page.
But the cpt is created and assigned to the selected category.
But when I go to a listing of all the created cpts, and click the assigned cat, I again end up on the 'Nothing Found' page.
Looking in the _term_relationships table, I see that the cpt ID and term_taxonomy_id are correct.
In wp_admin, in the cpt tab, the cpts are listed with the correct cat
and clicking one shows only those cpts in the same cat.
If I go to Posts > Categories, it shows zero posts in all categories.
If I remove the cat selector from the creation form, and do a submit, it refreshes to the page and gives me the success message.
In register_post_type, I have:
...
'taxonomies' => array('category'),
)
);
register_taxonomy_for_object_type('category', 'mycpt');
So I'm doing something wrong re the cat selector... or... ?