I recently migrated a blog from sub.domain.com to blogs.domain.com/sub/. Because I'm using Facebook comments, all the posts published before April 25 need to reference sub.domain.com/blog-entry-title as the fb:comments href.

I know how to display certain posts for my date range with this code:

      function filter_where($where = '') {
      //posts for Jan 1 to April 26, 2012
    $where .= " AND post_date >= '2012-03-01' AND post_date <= '2012-03-15'";
    return $where;
add_filter('posts_where', 'filter_where');

But can I manipulate this code to use at the template level to say: "If post published before April 25, display xyz comments; else display abc comments."

1 Answer 1


Sure, you can do something like this in your template code:

    $migrate_date = mktime(0,0,0,1,1,2012);
    if ( get_the_date('U') > date('U', $migrate_date) ) {
        echo "<p>New</p>\n";
    } else {
        echo "<p>Old</p>\n";
  • Hmm, that sesms right but not quite working.
    – lauren
    Apr 26, 2012 at 20:35
  • I added the code above to my template's single.php and tested on a few pages. It works.
    – cpilko
    Apr 26, 2012 at 21:32
  • Aha! I see what I did wrong; just needed to change the date. Thank you.
    – lauren
    Apr 26, 2012 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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