WP两个站点之间的简单饼图自定义字段


WP Simple Pie custom fields between 2 sites

我有两个网站。其中一个我正在使用ACF将自定义字段添加到自定义帖子类型"jobs"中,我在主站点上用键"job_type"设置了自定义字段。然后我将其添加到函数文件中:

/** Add ACF fields to RSS **/
add_action('rss2_item', 'cup_rss2_job');
function cup_rss2_job() {
    $post_id = get_the_ID();
    $job_link_url = get_field('job_link', $post_id);
    if($job_link_url){
        echo "<job_link>{$job_link_url}</job_link>'n";
    }
}

当我访问诸如http://my-domain.com/jobs/feed/我可以看到我现在可以访问<job_link>的值的位置。然而,在我使用SimplePie的网站上(同一服务器),我得到了以下错误:

WP_Error Object
(
    [errors] => Array
        (
            [simplepie-error] => Array
                (
                    [0] => This XML document is invalid, likely due to invalid characters. XML error: not well-formed (invalid token) at line 59, column 106
                )
        )
    [error_data] => Array
        (
        )
)

我知道,我用来获取提要的功能应该设置正确,因为我使用类似的功能在相同的网站上用一个单独的自定义字段获取另一个提要。这是我用于fetch_feed 的函数

function cup_jobs_feed($limit, $offset) {  
    $feed = fetch_feed( 'http://my-domain.com/jobs/feed/' );
    if ( ! is_wp_error( $feed) ):
        // Get a maximum of 1 item
        $maxitems = $feed->get_item_quantity( $limit );
        $items = $feed->get_items( $offset, $maxitems );
        foreach ( $items as $item ):
            $feedDescription = $item->get_content();
            $image = returnImage($feedDescription);
            $image = scrapeImage($image);
            $image_url= $item->get_permalink();
            $description = $item->get_description();
            $description = preg_replace("/<img[^>]+'>/i", "", $description); //strip img out of description
            $job_link = $item->get_item_tags('','job_link')[0]['data'];
            ?>
            <div class="row job-listing">
                <div class="col-md-4">
                    <div class="image-box"><?php echo '<a href="' . $image_url . '"><img class="aligncenter" src="' . $image . '" /></a>'."'n";?></div>
                </div>
                <div class="col-md-8 job-details">
                    <h4><a href="<?php echo $item->get_permalink(); ?>" target="_blank"><?php echo $item->get_title(); ?></a></h4>
                    <p><?php echo strip_tags($description); ?></p>
                    <p><?php
                        if($job_link){ ?>
                            <a href="<?php echo $job_link; ?>" target="_blank" title="Click Here to Register">Learn More</a>
                        <?php
                        } else { ?>
                            <a href="<?php echo $item->get_permalink(); ?>" target="_blank">Learn More</a>
                        <?php } ?>
                    </p>   
                </div>
                <hr>
            </div>
            <?php
        endforeach; 
    else: // Returned WP_Error, unable to fetch the feed.
    ?>
        <p>There was an error fetching the CUP Jobs, please try again later</p>
    <?php
    endif;
    ?>
<?php
}

通过XML验证器运行提要后,我发现其中一个job_link URL有"&",XML需要将其转换为html &#038;,这就是导致提要抛出无效字符错误消息的原因。

简而言之,如果我把它放在站点#1 http://google.com/view=mobile&location=1的自定义字段中,这将失败。正确的方法应该是:

http://google.com/view=mobile&#038;location=1