• Resolved Caridor

    (@shaar7)


    Hello,

    kindly i would like to let people able to post only 1 post for each phone number.
    so he will not be able to post another post if he already submitted post before using same number.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Saiful Islam

    (@saifislam01)

    Hi @shaar7,

    Thank you for reaching out to us with your query about restricting users to posting only one post per phone number using the WP User Frontend plugin.

    To achieve this functionality, you will need to implement a custom validation process that checks if the phone number entered by the user has already been used in a previous post.

    Hope this information will help.

    Regards!

    Thread Starter Caridor

    (@shaar7)

    thanks for fast reply.
    can you assist me to achieve it.

    i tried the below code:

    function restrict_one_post_per_phone_number($post_id, $form_id, $form_settings, $form_vars) {

    $phone_number = isset($_POST['meta key']) ? sanitize_text_field($_POST['meta key']) : '';


    if (empty($phone_number)) {
    return;
    }


    $existing_posts = new WP_Query(array(
    'post_type' => 'post',
    'meta_query' => array(
    array(
    'key' => '__________',
    'value' => $phone_number,
    'compare' => '='
    )
    )
    ));

    /
    if ($existing_posts->have_posts()) {

    wp_delete_post($post_id, true);


    wp_die('A post with this phone number already exists. You cannot submit more than one post with the same phone number.', 'Error', array('back_link' => true));
    }

    }
    add_action(‘wpuf_form_post_submitted’, ‘restrict_one_post_per_phone_number’, 10, 4);

    Plugin Support Saiful Islam

    (@saifislam01)

    Hi @shaar7,

    Based on your request, to achieve this, you may check the following code:

    function check_duplicate_phone_number($postdata) {
    // Extract phone number from the submitted data
    $phone_number = isset($postdata['your_phone_number_field']) ? $postdata['your_phone_number_field'] : '';

    if (empty($phone_number)) {
    return $postdata;
    }
    $args = array(
    'post_type' => 'your_post_type',
    'meta_query' => array(
    array(
    'key' => 'your_phone_number_field',
    'value' => $phone_number,
    'compare' => '='
    )
    )
    );

    $query = new WP_Query($args);

    if ($query->have_posts()) {
    // If a post with the same phone number exists, add an error
    wp_die(__('A post with this phone number already exists. Please use a different phone number.', 'your-textdomain'));
    }

    return $postdata;
    }
    add_filter('wpuf_add_post_args', 'check_duplicate_phone_number', 10, 1);

    I hope this helps. If it still doesn’t work, you may need to consider hiring a developer. I hope you understand.

    Best regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.