• how do I add action hook on form submit. In my understanding the code below makes sense but clearly it’s not working which means I’m doing it wrong. Can someone help me out with me?
    I want to store data from custom fields to DB on form submit from front-end.

    this is the code I have on function.php in custom theme folder.

    function add_location_info( $form_id, $post_id, $form_settings ){
    $fullstreet = $_POST['cf_street_number']. ' ' .$_POST['cf_route'];
        //enter information into the custom table //
        $wpdb->insert( $wpdb->prefix . 'places_locator',
    		array(
    				'post_id'		=> $post->ID,
    				'post_type' 	=> $post->post_type,
    				'post_title' 	=> $post_title,
    				'post_status'	=> $_POST['post_status'],
    				'street'		=> $fullstreet,
    				'city' 			=> $_POST['cf_locality'],
    				'state' 		=> $_POST['cf_administrative_area_level_1'],
    				'zipcode' 		=> $_POST['cf_postal_code'],
    				'country' 		=> $_POST['cf_country'],
    				'lat' 			=> $_POST['cf_lat'],
    				'long' 			=> $_POST['cf_lng'],
    			)
    		);
    
    }
    add_action("wpuf_post_submission", "add_location_info", 10, 3);
    add_action( 'wpuf_add_post_after_insert', 'wpuf_post_submission' );

    https://www.ads-software.com/plugins/wp-user-frontend/

Viewing 4 replies - 1 through 4 (of 4 total)
  • there is no such hook as wpuf_post_submission.
    you need:

    function add_location_info($post_id){
    $wpdb->insert( ... insert variables from $_POST ... to $post_id )
    }
    add_action( 'wpuf_add_post_after_insert', "add_location_info" );

    Thread Starter writegnj

    (@writegnj)

    I’m not familiar with action hook yet. so should I fix like this?

    function add_location_info($post_id){
        $fullstreet = $_POST['cf_street_number']. ' ' .$_POST['cf_route'];
        //enter information into the custom table //
        $wpdb->insert( $wpdb->prefix . 'places_locator',
    		array(
    				'post_id'		=> $post->ID,
    				'post_type' 	=> $post->post_type,
    				'post_title' 	=> $post_title,
    				'post_status'	=> $_POST['post_status'],
    				'street'		=> $fullstreet,
    				'city' 			=> $_POST['cf_locality'],
    				'state' 		=> $_POST['cf_administrative_area_level_1'],
    				'zipcode' 		=> $_POST['cf_postal_code'],
    				'country' 		=> $_POST['cf_country'],
    				'lat' 			=> $_POST['cf_lat'],
    				'long' 			=> $_POST['cf_lng'],
    			)
    		);
    
    }
    add_action( 'wpuf_add_post_after_insert', 'add_location_info' );// JavaScript Document

    I will try this and let u know!
    Thanks for the response.

    Thread Starter writegnj

    (@writegnj)

    I was missing
    global $wpdb;
    before the insert line. it WORKS good.
    @mainpart Thank you so much.

    Thread Starter writegnj

    (@writegnj)

    This got me to have more questions. lol so I see how to insert and replace data on database but I can’t figure it out how to delete data.

    it does not seem like have action hook for post delete, so I was trying to add below into wpuf-dashboard.php right after wp_delete_post( $_REQUEST['pid'] );

    global $wpdb;
    $post_id = $post->ID;
    $wpdb->delete( $wpdb->prefix . 'places_locator', array( 'post_id' => $post_id )  );

    Could u tell me what I;m doing wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add action hook function.’ is closed to new replies.