• Resolved Laneige90

    (@laneige90)


    Hi there.

    I’m having a few issues with some code of mine. This is my custom hook function in functions.php.

    function GrabExtraOrderInfo($args)
    {
        global $wpdb;
        $postid = (int)$args->id;
        $ExtraDimensions = get_post_meta(1872/*$postid*/,'_extraDimensions');
        $Shapeid = get_post_meta(1872/*$postid*/,'_shapeid',true);
        $shapeIdInt = (int)$Shapeid;
        $ShapeTable = $wpdb->prefix . "ShapeData";
    
        $url = $wpdb->get_results("SELECT $ShapeTable.url FROM $ShapeTable WHERE              id =$shapeIdInt");
    
        foreach($url as $chunks)
        {echo '<img src="' . $chunks->url . '"/>';}
    
        foreach ($ExtraDimensions as $values)
        {echo print_r($values);}
    
        die();
    }

    My problem is with the get_post_meta id under it’s first argument. If I put an integer directly as a parameter, the data I need is retrieved and it is echoed correctly. However, if I use my $postid variable, the function prints nothing. Now, if I debug the $postid variable it outputs the id I need correctly. I assumed that it must be due to it not being converted as an integer but my string to int conversion as made no difference.

    The parameter $args is the order object sent from the order email (woocommerce)

The topic ‘PHP variable issues’ is closed to new replies.