Hi,
which email(s) do you mean?
Usually, the best way to trigger some additional actions when Ad is saved in the database is to use the Post Status Transitions https://codex.ww.wp.xz.cn/Post_Status_Transitions
For example if you want to send some notification when Advert is pending or published you can use the below code
add_action( "pending_advert", function( $post_id ) {
wp_mail( get_option( "admin_email" ), "Ad is pending", "Ad is pending" );
} );
add_action( "publish_advert", function( $post_id ) {
wp_mail( get_option( "admin_email" ), "Ad published", "Ad published" );
} );
Thank you for your help.
I want to send a text message to the contact number in the advertisement to notify the user that the advertisement is about to expire. This is more timely and effective.
Send SMS function is like this:
function sendSms($adverts_phone,$adverts_person,$post_title)
{
....
}
How can I call it correctly?
You can send a text message when an Ad changes status from publish to expire with the below code
add_action( "publish_to_expire", function( $advert ) {
$adverts_phone = get_post_meta( $advert->ID, "adverts_phone", true );
$adverts_person = get_post_meta( $advert->ID, "adverts_person", true );
$post_title = $advert->post_title;
sendSms($adverts_phone,$adverts_person,$post_title)
} );
Thank you for your help. I wish you well!