admin管理员组文章数量:1291029
I'm trying to setup a custom RSS feed for attachments with a meta field. I succeeded in making the feed, however it's now overwriting the actual site content.
add_action( 'init', 'add_custom_feed' );
function add_custom_feed() {
add_feed( 'photos', 'render_photos_feed');
}
function render_photos_feed() {
//WP_Query for attachment
get_template_part( 'rss', 'photos' );
}
I have a poor understanding of where exactly a url is created here. What I'm expecting is example/photos/feed
or example/feed/photos
. I'm getting example/feed/photos
but then also example/photos
, which is where the Page that displays my photos exists. I can flush permalinks and turn off the action for this feed and render my page, but when it's online, I can see on the Photos page that its permalinked to photos-2
. I can't find any documentation online about why that happens.
I really don't want to create a CPT for these, the workflow of adding a checkbox was really easy & reduces noise on the backend and the WP Query works. Secondarily, I also am wondering if it's possible to change the main feed to be posts & photos. I can't just hijack the feed WP_Query because its an OR logic (get posts or attachment w/ meta value). Any thoughts there are welcome too.
I'm trying to setup a custom RSS feed for attachments with a meta field. I succeeded in making the feed, however it's now overwriting the actual site content.
add_action( 'init', 'add_custom_feed' );
function add_custom_feed() {
add_feed( 'photos', 'render_photos_feed');
}
function render_photos_feed() {
//WP_Query for attachment
get_template_part( 'rss', 'photos' );
}
I have a poor understanding of where exactly a url is created here. What I'm expecting is example/photos/feed
or example/feed/photos
. I'm getting example/feed/photos
but then also example/photos
, which is where the Page that displays my photos exists. I can flush permalinks and turn off the action for this feed and render my page, but when it's online, I can see on the Photos page that its permalinked to photos-2
. I can't find any documentation online about why that happens.
I really don't want to create a CPT for these, the workflow of adding a checkbox was really easy & reduces noise on the backend and the WP Query works. Secondarily, I also am wondering if it's possible to change the main feed to be posts & photos. I can't just hijack the feed WP_Query because its an OR logic (get posts or attachment w/ meta value). Any thoughts there are welcome too.
Share Improve this question edited Jun 8, 2021 at 0:38 HarrisonFM asked Jun 8, 2021 at 0:21 HarrisonFMHarrisonFM 133 bronze badges1 Answer
Reset to default 0You can use feed/photos
with add_feed
. This rule will prevent the overwrite permalinks issue. Change your function like below and flush rewrite rules.
add_action( 'init', 'add_custom_feed' );
function add_custom_feed() {
add_feed( 'feed/photos', 'render_photos_feed');
}
function render_photos_feed() {
//WP_Query for attachment
header("Content-type: text/xml"); // Added for XML output
get_template_part( 'rss', 'photos' );
}
本文标签: Custom RSS Feed Overwrites Permalink
版权声明:本文标题:Custom RSS Feed Overwrites Permalink 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741517750a2382994.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论