Forum Replies Created
-
AuthorPosts
-
pixel016Member
Hooooo thanks you so so so so much Khaled it is working perfectly !
It has not been easy, thank you for your patience and participation.
pixel016MemberI can’t add my script to another page that will be called after the init ? it will solve all the problems no ?
pixel016Memberi’m not sure to understand, i’m trying something like this but i think it’s not that you say :
add_action( 'user_register', 'loadAfterUserRegistrationHook' ); function loadAfterUserRegistrationHook($user_id){ add_action( 'user_meta_after_user_register', 'createNewPost'); } function createNewPost( $response ){ global $userMeta; $userID = $response->ID; $user = new WP_User( $userID ); $role = $userMeta->getUserRole(); if( $role = 'artiste' ){ $newPost = array( 'post_title' => $user->nickname, 'post_content' => $user->description, 'post_status' => 'pending', 'post_author' => $userID, 'post_type' => 'cpt_artists', ); $post_id = wp_insert_post( $newPost ); error_log('Post ID : '.$post_id); wp_set_object_terms( $post_id, array('dj'), 'artist-category'); } }
pixel016MemberI work in local so i don’t have ftp login for the moment.
pixel016MemberPlease i need help
pixel016MemberAnd when i copy paste your code `add_action( ‘init’, ‘loadAfterUserRegistrationHook’ );
function loadAfterUserRegistrationHook(){
add_action( ‘user_meta_after_user_register’, ‘createNewPost’ );
}function createNewPost( $response ){
echo $response->user_login;
}`i don’t have the echo … so weird
pixel016Memberhmmm me too : in my function.php here is :
add_action( 'init', 'loadAfterUserRegistrationHook' ); function loadAfterUserRegistrationHook(){ add_action( 'user_meta_after_user_register', 'createNewPost' ); } function createNewPost( $response ){ global $userMeta; $userID = $response->ID; $user = new WP_User( $userID ); $role = $userMeta->getUserRole(); if( $role = 'artiste' ){ // Assume you have custom role named 'artist' $newPost = array( 'post_title' => $user->nickname, 'post_content' => $user->description, 'post_status' => 'pending', 'post_author' => $userID, 'post_type' => 'cpt_artists' ); $post_id = wp_insert_post( $newPost ); error_log('Post ID : '.$post_id); wp_set_object_terms( $post_id, array('dj'), 'artist-category'); } }
And no new post and no Post id log.
- This reply was modified 10 years, 10 months ago by pixel016.
pixel016MemberThanks Khaled but it’s not working, function createNewPost is not executed.
pixel016MemberI found part of the solution : The function.php file is loaded beafore the init of wordpress, so custom taxonomy are not “available”.
I have tried to change
add_action( 'user_meta_after_user_register', 'createNewPost' );
toadd_action( 'init', 'createNewPost' );
but i have errors (header already send).The plugin support can help me ?
pixel016MemberI think i can’t use the custom taxonomy because i’m on the functions.php file and this file is loaded before init.
Can you help ?
pixel016MemberI have a last question :
I can’t set terms of my custom taxonomy. If i use this code :
$userID = $response->ID; $user = new WP_User( $userID ); $role = $userMeta->getUserRole(); //$catId = get_cat_ID("dj"); if( $role = 'artiste' ){ $newPost = array( 'post_title' => $user->nickname, 'post_content' => $user->description, 'post_status' => 'pending', 'post_author' => $userID, 'post_type' => 'cpt_artists', 'tax_input' => array('artist-category' => array('dj') )); $post_id = wp_insert_post( $newPost ); wp_set_post_terms( $post_id, array( 'dj'), 'artist-category'); }
It doesn’t work.
I test this :
wp_get_post_terms($post_id, 'artist-category', array("fields" => "all"));
and the result is :
WP_Error Object ( [errors] => Array ( [invalid_taxonomy] => Array ( [0] => La taxinomie est invalide ) ) [error_data] => Array ( ) )
Why my custom taxonomy “artist-category” is invalid ??
pixel016MemberI’m sure someone know how to 🙂
pixel016MemberHooo perfect ! Thanks you very much for you help, really !
King regards
pixel016MemberThank you very much for your help.
Can you explain to me how to use UMP hook to create custom post type for each artist ?
Thanks
-
AuthorPosts