admin管理员组

文章数量:1124409

I am trying to display posts from one web site to another using REST API. I was able to display all element except ACF field 'broj_epizode'. Code so far:

<?php
define('HOURS', 60 * 60 * 12);

function get_remote_api_data() {
    global $apiData;
    if (empty($apiData)) $apiData = get_transient('api_data');
    if (!empty($apiData)) return $apiData;

    $response = wp_remote_get(';_embed&acf_format=standard', array(
        'timeout' => 20,
    ));
    $data = wp_remote_retrieve_body($response);

    if (empty($data)) return false;

    $apiData = json_decode($data);

    set_transient('api_data', $apiData, HOURS);

    return $apiData;
}

$feed = get_remote_api_data();
if ($feed) : ?>
    <?php foreach ($feed as $post) : ?>
        <?php 
            $title = $post->title->rendered;
            $image = $post->_embedded->{'wp:featuredmedia'}[0]->media_details->sizes->{'full'}->source_url;
            $excerpt = $post->excerpt->rendered;
            $link = $post->link;

            // Retrieve ACF custom field value 'broj_epizode'
            $acf_data = isset($post->acf) ? $post->acf : '';
            $post_number = isset($acf_data->broj_epizode) ? $acf_data->broj_epizode : '';

            // Retrieve custom taxonomy term
            $taxonomy_name = '';
            $taxonomy_slug = ''; // Initialize taxonomy slug variable
            if (isset($post->_embedded->{'wp:term'})) {
                $taxonomy = $post->_embedded->{'wp:term'};
                foreach ($taxonomy as $term) {
                    foreach ($term as $item) {
                        if ($item->taxonomy === 'kanal') {
                            $taxonomy_name = $item->name;
                            $taxonomy_slug = $item->slug; // Assign slug value
                            break 2;
                        }
                    }
                }
            }
        ?>
        <div class="col-lg-6 col-xl-4">
            <div class="video-item"> 
                    <div class="post-thumbnail">
                        <a href="<?php echo $link; ?>"><img src="<?php echo $image; ?>" class="poster" alt="<?php echo $title; ?>" ></a>
                    </div>
                    <div class="caption">
                        <!-- Display custom taxonomy term above the title -->
                        <h5 class="taxonomy"><?php echo $post_number; ?> <a href="/<?php echo $taxonomy_slug; ?>" target="_blank"><?php echo $taxonomy_name; ?></a></h5> 
                        <a href="<?php echo $link; ?>"><h2><?php echo $title; ?></h2></a>
                    </div>
            </div>    
        </div>
    <?php endforeach?>
<?php endif; ?>

Please help!

本文标签: Displaying posts from one web site to another using REST API