Hey @ajengwidya,
We do fire a hook after successful user creation. Its a action hook: ‘atbdp_user_registration_completed’ and the it has the $user_id as argument.
So I guess you can do something like this:
add_action("atbdp_user_registration_completed" function($user_id) {
//do stuff here
});
Regards,
Mahdi.
Hi, @m4hd1bd
Thank you for the quick response!
Ok then. Actually, I want something like this:
add_action("user_register", function($user_id) {
//create a new listing (type 'at_biz_dir') using WP hook or Directorist hook (if any)
});
What are the hooks should I use to create the at_biz_dir post and the postmeta as well?
Hi @ajengwidya,
You can insert a post using the wp_insert_post() function, you can also get the post id after you insert the post so that you can then use the update_post_meta() function to add/update the meta values.
$post_id = wp_insert_post( $post, $wp_error );
Learn more here: https://developer.ww.wp.xz.cn/reference/functions/wp_insert_post/
And here: https://developer.ww.wp.xz.cn/reference/functions/update_post_meta/
Regards,
Mahdi.
Hi, @m4hd1bd
Will it be assumed as Directorist’s new listing if I define the post type as ‘at_biz_dir’?
Hi, @m4hd1bd
Ok. I will try it and will let you know if I have more questions. Thank you!
Hi, @m4hd1bd
I successfully create new listing as I add new user. The problem is when I try to view the listing, the data doesn’t displayed even though I already store the post_type as ‘at_biz_dir’ as well the postmeta data. Please check: https://prnt.sc/AUvUnoZwKnC9
In order to display the data, I have to update the listing.
Did I miss some steps?
Hi @ajengwidya,
Make sure to add the ‘_directory_type’ meta to the listings, that would be the ID of the directory type. Otherwise, it won’t know where to get the layout for Single Listing Page to get.
Regards,
Mahdi.
Hi, @m4hd1bd
Based on my case, I also set the wp_set_object_terms() besides the ‘_directory_type’ meta. It works well on my end. Thank you!
Also, how to use Directorist’s action/filter hook? I try this:
add_action('atbdp_listing_updated', 'my_listing_update');
But nothing seems to work.
Hi @ajengwidya,
That is the correct way. Here ‘my_listing_update’ would be a function that you’ll have to define. But please note that this particular hook, ‘atbdp_listing_updated’, only gets fired when you’re editing a listing on the frontend and then saving it.
Regards,
Mahdi.