Try adding ‘&post_type=any’ to the rewrite rule and show me the query.
Thread Starter
Jeff
(@jhanbycarrolltongroupcom)
I don’t see any changes.
WP_Query Object
(
[query_vars] => Array
(
[feed] => feed
[school] => lycee-francais
[post_type] => school
[name] => lycee-francais
[error] =>
[m] => 0
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author_name] =>
[tb] =>
[paged] => 0
[comments_popup] =>
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[fields] =>
[menu_order] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
)
[tax_query] =>
[meta_query] =>
[post_count] => 0
[current_post] => -1
[in_the_loop] =>
[comment_count] => 0
[current_comment] => -1
[found_posts] => 0
[max_num_pages] => 0
[max_num_comment_pages] => 0
[is_single] => 1
[is_preview] =>
[is_page] =>
[is_archive] =>
[is_date] =>
[is_year] =>
[is_month] =>
[is_day] =>
[is_time] =>
[is_author] =>
[is_category] =>
[is_tag] =>
[is_tax] =>
[is_search] =>
[is_feed] => 1
[is_comment_feed] => 1
[is_trackback] =>
[is_home] =>
[is_404] =>
[is_comments_popup] =>
[is_paged] =>
[is_admin] =>
[is_attachment] =>
[is_singular] => 1
[is_robots] =>
[is_posts_page] =>
[is_post_type_archive] =>
[query_vars_hash] => 7832e8aa476657087351138dffd158ec
[query_vars_changed] =>
[thumbnails_cached] =>
[query] => Array
(
[feed] => feed
[school] => lycee-francais
[post_type] => school
[name] => lycee-francais
)
)
testing
Quick question: have you flushed your rewrite rules at all? You’re supposed to do that every time you tweak a rewrite rule.
Thread Starter
Jeff
(@jhanbycarrolltongroupcom)
Yep. From the Rewrite Rules Inspector plugin: http://screencast.com/t/BVAFQHEqK
You may have to bring ‘pre_get_posts’ back into the mix so you can remove the ‘post_type’ and the ‘name’ query variable.
This means you can remove ‘&post_type=any’ from the rewrite rule.
add_action( 'pre_get_posts', 'my_website_pre_get_posts' );
function my_website_pre_get_posts( &$query ) {
// There's a 'feed' query variable that lets you
// know you're running a feed so you can only run
// your code during a feed.
if ( $feed = get_query_var( 'feed' ) ) {
// You should also have a query variable for
// 'schools' set to whatever the school name is
if ( $school = get_query_var( 'school' ) ) {
unset( $query[ 'post_type' ] );
unset( $query[ 'name' ] );
}
}
}
Thread Starter
Jeff
(@jhanbycarrolltongroupcom)
I think caching was working against me. I don’t need the pre_get_posts hook anymore. Simply removing &post_type=any from the rewrite rule seems to have solved the problem.
Here is the working code:
add_action( 'wp_loaded', 'largo_child_rewrite_rules' );
function largo_child_rewrite_rules() {
add_rewrite_rule( '^school/([^\/]+)/feed/?$','index.php?feed=feed&school=$matches[1]&cpt_onomy_archive=1', 'top' );
}
Proof: http://lensnola.staging.wpengine.com/school/lycee-francais/feed/
It looks like you might be messing with your site because it’s throwing a fatal error… but if you say it’s working, then hooray!
Darn that caching! I’ve had several instances where caching was the problem. When it helps, it helps… but when it gets in the way? It usually means you spent forever figuring that out!
Thread Starter
Jeff
(@jhanbycarrolltongroupcom)
I was/still kind of am, but that link should work now.
Thread Starter
Jeff
(@jhanbycarrolltongroupcom)
No problem. Glad I could help. 🙂