Replies: 0
Trying to create a setup where a remote server calls a webpage and POSTs some data. That custom PHP page is configured to create a new ToDo item. It does it fine EXCEPT for setting the category correctly.
The relevant portions of the code:
define( 'WP_USE_THEMES', false );
require_once( $_SERVER[ 'DOCUMENT_ROOT' ] . '/wp-load.php' );
require_once( $_SERVER[ 'DOCUMENT_ROOT' ] . '/wp-admin/includes/post.php' );
...
...
$a2z3_entry_post = array(
'post_type' => 'todo',
'post_title' => $a2z3_entry_POSTTITLE,
'post_content' => $a2z3_entry_POSTCONTENT,
'post_status' => 'publish',
'post_author' => 1, // the admin is the author
'comment_status' => 'closed',
'ping_status' => 'closed',
);
// this works
$a2z3_entry_post_id = wp_insert_post( $a2z3_entry_post, true, false );
// these work as well
add_post_meta( $a2z3_entry_post_id, '_status', 0, true );
add_post_meta( $a2z3_entry_post_id, '_priority', 1, true );
add_post_meta( $a2z3_entry_post_id, '_assign', -1, true );
add_post_meta( $a2z3_entry_post_id, '_deadline', '', true );
add_post_meta( $a2z3_entry_post_id, '_progress', 0, true );
// these did NOT work, a2zq3_cat_id is the category id (number), a2zq3_cat_name is the category name (string). Both are defined correctly.
wp_set_object_terms( $a2z3_entry_post_id, $a2zq3_cat_id, 'todocategories');
wp_set_object_terms( $a2z3_entry_post_id, $a2zq3_cat_id, $a2zq3_cat_name);
wp_set_object_terms( $a2z3_entry_post_id, $a2zq3_cat_id, 0);
wp_update_term( $a2zq3_cat_id, 'todocategories', array( 'name' => $a2zq3_cat_name ) );
do_action( 'add_term_relationship', $a2z3_entry_post_id, $a2zq3_cat_id, 0);
Apologies – am new to WordPress development, so might be missing something obvious here…