0

I am writing a plugin that is modifying the RSS2 feed for a podcast that uses a custom post type.

After the query runs (on action hook template_redirect; See this question for why), I'm checking to see if the request is for an archive of my custom post type. If so, I add actions and filters to modify the RSS2 template.

Now I would like to make some modifications that affect the query. Without using the is_post_type_archive function, which is only updated after the query runs, how do I check that the request is for an archive of the custom post type? On which hook would I add this?

Here is the relevant code I have so far:

add_action('template_redirect', 'myplugin_frontend_init_after_query');

function myplugin_frontend_init_after_query() {
    if ( is_post_type_archive('myplugin_custom_type') ) {
        add_action('rss2_ns', 'myplugin_podcast_ns');
        add_action('rss2_head', 'myplugin_podcast_head');
        add_filter('the_excerpt_rss', 'myplugin_podcast_description_filter');
        // other actions and filters here
        // The next one is the one I'm having trouble with:
        add_filter('option_posts_per_rss', 'myplugin_podcast_number_filter');
        // I'm attempting to alter the number of posts in the feed, but of course after the query runs, it is too late.
    }
}
1

Use the hook pre_get_post see codex

| improve this answer | |
  • Nice! And as a bonus, the is_post_type_archive function works there as well, so I can just move the entire thing from the template_redirect hook to the pre_get_post hook. Thanks. – Ben Miller - Remember Monica Aug 15 '13 at 19:33

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.