• I’m creating a new blog post through a template. I do that with the following code:

    if($_POST['category_name'] != ''){
        $cat_ids = $_POST['category_name'];
    }
    $bmt_post = array(
        'post_title'    => wp_strip_all_tags( $title ),
        'post_content'  => wp_strip_all_tags( $information ),
        'post_status'   => 'publish',
        'post_category' => array( $cat_ids )
    );
    
    // Insert the post into the database
    $post_id = wp_insert_post( $bmt_post );

    When I do this it doesn’t send en email using the Subscribe2 plugin. If I create the post from the Admin section the email is sent though. How can I send an email using the Subscribe2 plugin outside of the admin section?

    https://wordpress.org/plugins/subscribe2/

Viewing 1 replies (of 1 total)
  • @treeleaf20,

    In theory that should work but I suspect some glitches may come from the category_name handling.

    If only one category is selected for category_name then what is passed will be a string, if more than one category is selected then an array is passed, you need to account for that in the assignment of the $cat_ids variable. Maybe something like this:

    if ( isset( $_POST['category_name'] ) ) {
        if ( is_array( $_POST['category_name'] ) ) {
            $cat_ids = $_POST['category_name'];
        } else {
            $cat_ids = (array) $_POST['category_name'];
        }
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Send email using Subscribe2 with wp_insert_post not in Admin section’ is closed to new replies.