I'm working on a plugin that will create a custom post type for press releases. The objective is to give the user the ability to easily create a press release in the standard press release format. An example would be:


Title Here

City, State (Month Year) - Paragraph 1

Paragraph 2

So on...

PR Rep Name
Phone: #
Fax: #

# # #

The plugin has custom fields for the contact info, automatically prepends the "FOR IMMEDIATE RELEASE", etc. The whole idea is that you just write the content for the release and everything else is taken care of for you.

I am trying to create a custom RSS feed for this post type which will use these custom fields and display everything correctly. I have it basically working except for one bug I'm noticing.

If multiple press releases were published on the same day, only the most recent will show the date. The rest are blank where the date should appear. Here is my code for the feed: (modified version of /wp-includes/feed-rss2.php)


header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$more = 1;

echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>

<rss version="2.0"
    <?php do_action('rss2_ns'); ?>

    <title><?php bloginfo_rss('name'); ?></title>
    <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    <link><?php bloginfo_rss('url') ?></link>
    <description><?php bloginfo_rss("description") ?></description>
    <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
    <language><?php bloginfo_rss( 'language' ); ?></language>
    <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
    <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
    <?php do_action('rss2_head'); ?>
    while( have_posts()) : the_post();
    $pr_option = get_option('bacpr_option');
    $pr_meta = get_post_custom();
    $pr_date_format = ($pr_option["date_format"] != null && $pr_option["date_format"] != "") ? $pr_option["date_format"]:"F j, Y";
        <title><?php the_title_rss() ?></title>
        <link><?php the_permalink_rss() ?></link>
        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
        <?php the_category_rss('rss2') ?>

        <guid isPermaLink="false"><?php the_guid(); ?></guid>


    $content = "<p><strong>FOR IMMEDIATE RELEASE</strong></p><h1>".the_title_rss()."</h1>";

    if ($pr_meta["insert_summary"][0] == 1) {
        $content .= "<p><em>".$pr_meta["summary"][0]."</em></p>";

    $original_content = ob_get_contents();

    $startpos = strpos($original_content, "<p");
    $endpos = strpos($original_content, ">", $startpos);

    $new_content = substr($original_content, 0, $endpos+1);
    $new_content .= "<strong>".$pr_meta['location'][0]."&nbsp;".the_date($pr_date_format, '(', ')', false)."&nbsp;-</strong>&nbsp;";
    $new_content .= substr($original_content, $endpos+1);

    $content .= $new_content;

    $content .= "<p>Contact:<br/>";
    $content .= ($pr_meta["signature1"][0] != null || $pr_meta["signature1"][0] != "") ? $pr_meta["signature1"][0]."<br/>":"";
    $content .= ($pr_meta["signature2"][0] != null || $pr_meta["signature2"][0] != "") ? $pr_meta["signature2"][0]."<br/>":"";
    $content .= ($pr_meta["signature3"][0] != null || $pr_meta["signature3"][0] != "") ? $pr_meta["signature3"][0]."<br/>":"";
    $content .= ($pr_meta["email"][0] != null || $pr_meta["email"][0] != "") ? "<a href='mailto:".$pr_meta["email"][0]."'>".$pr_meta["email"][0]."</a>"."<br/>":"";
    $content .= ($pr_meta["address1"][0] != null || $pr_meta["address1"][0] != "") ? $pr_meta["address1"][0]."<br/>":"";
    $content .= ($pr_meta["address2"][0] != null || $pr_meta["address2"][0] != "") ? $pr_meta["address2"][0]."<br/>":"";
    $content .= ($pr_meta["address3"][0] != null || $pr_meta["address3"][0] != "") ? $pr_meta["address3"][0]."<br/>":"";
    $content .= ($pr_meta["phone"][0] != null || $pr_meta["phone"][0] != "") ? "Phone: ".$pr_meta["phone"][0]."<br/>":"";
    $content .= ($pr_meta["fax"][0] != null || $pr_meta["fax"][0] != "") ? "Fax: ".$pr_meta["fax"][0]."<br/>":"";
    $content .= ($pr_meta["web"][0] != null || $pr_meta["web"][0] != "") ? "<a href='".$pr_meta["web"][0]."'>".$pr_meta["web"][0]."</a>"."<br/>":"";
    $content .= "</p><p><strong>";
    $content .= ($pr_option["ends_with"] == 2) ? "ENDS":"# # #";
    $content .= "</strong></p>";


    <content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>

<?php rss_enclosure(); ?>
    <?php do_action('rss2_item'); ?>
    <?php endwhile; ?>

Basically I'm at a loss and I thought I'd turn to you folks for help. Thanks in advance to anyone who helps me out here.



When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string. Use to add the date set in the admin interface.

What you want is this:

$new_content .= "<strong>".$pr_meta['location'][0]."&nbsp;(".get_the_date($pr_date_format).")&nbsp;-</strong>&nbsp;";
|improve this answer|||||
  • 1
    Thank you very much Nicholas. As you know, this was just the fix I needed. I was a little embarrassed to click that link though. I can't believe how simple this should have been! – Brett Clapper Feb 25 '13 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.