• Resolved payamdigi

    (@payamdigi)


    hi there,
    thanks for your great plugin.

    I want to get the original post id, using generated custom number by your plugin.

    in fact I have (custom order number) and I want to get ($post_id) of this order.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author tychesoftwares

    (@tychesoftwares)

    Hi @payamdigi,

    You can get post_id using following code:

    global $wpdb;
    $prepare_guery = "SELECT post_id FROM ".$wpdb->prefix."postmeta where meta_key ='_alg_wc_full_custom_order_number' and meta_value like '%%Mz_1026%'";
    $get_values = $wpdb->get_col( $prepare_guery );
    $origion_post_id = $get_values[0];

    Please replace ‘Mz_1026’ with your custom order number.

    Thread Starter payamdigi

    (@payamdigi)

    hi @tychesoftwares

    I already used this code and it works perfectly:

    
    $args = array(
    	'post_type' => 'shop_order',
    	'post_status' => 'any',
     	'meta_query' => array(
    		array(
    			'key' => '_alg_wc_custom_order_number',
    			'value' => $order_number,
    			'compare' => '=',
    		)
    	)
    );
    $query   = new WP_Query( $args );
    if ( !empty( $query->posts ) ) {
    	$order_id = $query->posts[ 0 ]->ID;
    }
    

    is it ok?

    Plugin Author tychesoftwares

    (@tychesoftwares)

    Hi @payamdigi,

    Yes, this is also the correct way for fetching post_id.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get the original post ID’ is closed to new replies.