Wordpress不显示数据库中的信息

I'm very new to both PHP and Wordpress and I'm trying to fetch info from a database and display it in various places on the page. The page formats well, but it's not populating it with info from the database. I'm totally at a loss! I have a feeling that the problem lies somewhere in this portion of the code:

<?php
function objectToArray($form_obj) {

    if (is_object($form_obj)) {
        $form_obj = get_object_vars($form_obj);
    }

    if (is_array($form_obj)) {
        return array_map(__FUNCTION__, $form_obj);
    } else {
        return $form_obj;
    }

}

function get_data($url) {
    $ch = curl_init();
    $timeout = 31;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
?> 

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        $query_string = $_SERVER['QUERY_STRING'];
        $query_vars = explode("=", $query_string);
        $id = $query_vars[1];
        $catalog = get_data('key to database is here');
        $catalog_item = json_decode($catalog_item);
        $catalog_item = objectToArray($catalog_item);
        $catalog_item = $catalog_item['rows'][0]['value'];
        ?>
        <?php while ( have_posts() ) : the_post(); ?>
        <article id="post-<?php the_ID(); ?>"
        <?php post_class(); ?>>
        <?php
        $directory_path = getcwd() . '/wp-content/uploads/';
        ?>
        <header class="entry-header">
            <?php
            $IMG_name = 'IMG-' . $catalog_item['c_cat_no'] .'.gif';
            if( file_exists($directory_path . $IMG_name) ){
            ?>
                <img src="/wp-content/uploads/<?=$IMG_name;?>" />
                <?php
            }
            ?>