• Resolved Jack

    (@jack1132132)


    Hello,

    I have two meta values for the posts created with Forminator, and I need to know in which order does Forminator, when creating the post, add these meta fields.

    I have the ‘upload-1’ field and the ‘currency-1’ field, as show in the picture below.

    View post on imgur.com

    View post on imgur.com

    Does add_post_meta( $post_id, 'upload-1', $value ); happen before add_post_meta( $post_id, 'currency-1', $value ); due to the order in the custom fields?

    I need to know because I have to determine if the hook ‘added_post_meta’ fires first with the ‘upload-1’ meta field or with the ‘currency-1’ field.

    thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @jack1132132

    I hope you are doing well.

    Since you are mapping the custom meta it will get the order that you insert in the settings and create a loop on it:

    
    $post_meta   = isset( $data['post-custom'] ) ? $data['post-custom'] : '';
    
    if ( ! empty( $post_meta ) ) {
    				foreach ( $post_meta as $meta ) {
    					add_post_meta( $post_id, $meta['key'], $meta['value'] );
    				}
    				add_post_meta( $post_id, '_has_forminator_meta', true );
    			}

    You can also confirm it using this PHP code:

    add_action( 'added_post_meta', 'verify_metadata_order_forminator', 10, 4 );
    
    function verify_metadata_order_forminator( $mid, $object_id, $meta_key, $_meta_value ){
    
        $content = $meta_key . ' ' . date('h:i:s');
    
    	error_log( print_r( $content, true ) );
    }

    It will print in the debug.log when that post meta was fired.

    Best Regards
    Patrick Freitas

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @jack1132132 ,

    We haven’t heard from you for a while now, so it looks like you don’t have any more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘In what order does the Forminator add post metas on creating posts?’ is closed to new replies.