Blog feed inexplicably showing up on all pages

I’m encountering a really weird problem that I’ve never seen in any of my dozens of uses of Sage 8. All pages except for the home page and custom post types are showing a blog feed, and I have no idea why. I’m occasionally able to resolve the problem, but it occasionally comes back. And I have no idea what fixes/breaks it.

A few additional details:

  • I just did a fresh replacement of my local database with that from our staging environment, and it caused the issue to start again. I suppose this could mean the problem lies in the database.
  • “Settings » Reading » Posts page” is not currently set to any page. It was previously set to a page called Blog, but that didn’t make a difference in any case.
  • The pages in question are set to a custom template using Page Attributes.
  • Despite this, adding <?php echo get_page_template(); ?> to base.php returns "/wp-content/themes/[theme-name]/page.php.
  • Changing the pages from my custom template to the default template (and back) has no effect. It still shows the blog feed.
  • I started this project by cloning the existing website and implementing Sage, rather than using a fresh WordPress install. This was largely done to make content and image migration from their existing website easier. I also tried a fresh install of WordPress and migrated content using WordPress’ export tool, but the issue still persisted (which makes me think its a problem in the file structure).
  • I have quite a bit going on in extras.php. You can view that here: https://gist.github.com/camtheperson/2c8e36b9294b99d5b838d856ea234c31

To me, it seems like WordPress’ template hierarchy is somehow… broken. It is completely ignoring the fact that these pages are set to a custom template, so it shouldn’t be falling back to page.php.

Any suggestions for what direction I should head or things I should try to continue troubleshooting this problem would be GREATLY appreciated. Thanks.

Two things in your extras.php looked like they might have something to do with this:

#1

function manage_episodes_columns($column, $post_id) {
  if ($column == 'program') {
    if ($program = get_field('program', $post_id)) {
      $post = $program;
      setup_postdata($post);
      echo $post->post_title;
      wp_reset_postdata();
    }
  } else {
    _e('No Program Assigned');
  }
}

This is messing with the global $post which seems like the kind of thing that can break the loop. I’m not sure it’s even necessary here: I think the following should still achieve the same effect:

function manage_episodes_columns($column, $post_id) {
  if ($column == 'program') {
    if ($program = get_field('program', $post_id)) {
      echo $program->post_title; // or $program['post_title'] depending on the way it's returned
    }
  } else {
    _e('No Program Assigned');
  }
}

#2
I can’t say for sure if this would cause a problem, because I’m very bad at parsing regex and remembers how permalinks work, but I’ve run into many problems when setting up my own re-writes. That, and the fact that you’ve hooked this into init make me think it could be causing a problem.

1 Like

#1 Redid the mark up for that function. It still works like I need it to, but didn’t fix the issue, even after clearing cache.

#2 Turns out commenting out the add_directory_rewrite() and episode_rewrite() functions in extras.php and then flushing WordPress rewrite rules did the trick. It’ll jack up how I’ve set up my episode permalinks, but it’s a start. Thanks!

1 Like

So I’ve determined the problem goes away and comes back based on this particular function from extras.php:

// Custom program permalink for episodes
function add_directory_rewrite() {
  global $wp_rewrite;
  add_rewrite_tag('%program%', '(.+)');
  add_rewrite_rule('^program/(.+)/episode/(.+)/', 'index.php?p=$matches[2]&program=$matches[1]', 'top');
  add_permastruct('program', '%program%');
}
add_action('init', __NAMESPACE__ . '\\add_directory_rewrite');

After playing around with it for a bit, commenting out the following line “fixed” it:

// add_permastruct('program', '%program%');

… I still have no idea why that would cause the blog feed to appear on all pages, but it appears to be the issue because it is solving the problem. Nothing in add_permastruct()'s function reference looks like it would cause that type of issue, but who knows.

My first thought was that maybe your regular expressions are too broad and something like this would be worth trying:

function add_directory_rewrite() {
  global $wp_rewrite;
  add_rewrite_tag('%program%', '([^/]*)');
  add_rewrite_rule('^program/([^/]*)/episode/([^/]*)/', 'index.php?p=$matches[2]&program=$matches[1]', 'top');
  add_permastruct('program', '%program%');
}

But that may not be the case if it works without add_permastruct.

In the examples I’ve seen for add_permastruct they usually have something more like this:

add_permastruct('program', '/program/%program%');

You could try something along those lines.

1 Like

I’m running into this exact issue with a brand new install of Radicle. Everything works with “Plain” permalinks set, but when “Post name” is set, all pages other than the homepage, or archives, show the posts feed.

Back to working now, but for reasons unknown, perhaps an unrelated wp acorn view:clear did the trick.