• I have succeeded in moving all of my many customizations of WordPress into a custom plugin except 1: I have an if condition in the RSS2 feed right inside “The Loop” to prevent unpublished posts to be displayed in the feed. (This is a workaround due to modifying the Search Everything plugin to include unpublished posts for logged in users, which then, however, allowed them to show up in a search term feed (…/?s=keyword&feed=rss2) for everyone. I think that was why it’s there.)

    I was wondering if there is any way, short of replacing the entire feed script, to filter in such an if enclosure. It would go right after “while(have_posts()): the_post();” and before “<item>” and end right before “endwhile;” and after “</item>”.

    Alternatively, can I replace the entire Loop (and only The Loop) in the rss feed via a plugin filter?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Are non logged in users able to see the search feed posts that aren’t published? Because from the way you are describing your problem, your best solution might be to fix the query modification to work properly, not the rss feed.

    Thread Starter ericr23

    (@ericr23)

    Yes, that was apparently the problem. Nonlogged-in users were seeing unpublished posts in the search results. The same if condition is on the index page.

    The if condition is “((get_post_status()==’publish’) || ((get_post_status()!=’publish’) && current_user_can(‘edit_posts’)) || !is_search())”.

    You’re right: it would be better to modify the search plugin. I think the problem was complicated because it uses SQL queries, so where to add the logged-in user condition is not as obvious as the other modifications. I don’t remember if I asked the plugin author or other users for help.

    Moderator bcworkz

    (@bcworkz)

    I too agree that the correct query is preferable to throwing out data in the loop, but for the sake of more information, you can create your own custom feed to replace the core feed, in which you can modify the loop any way you desire. Custom Feeds

    Thread Starter ericr23

    (@ericr23)

    Thanks. I already have a couple of custom feeds, but in this case, I was hoping to avoid that route, since the only customization is a conditional statement. But if I can’t figure out or get shown how to modify the search plugin, I guess I’ll take that road.

    Or, if I really feel like shirking my paying work, try writing my own search plugin!

    Thread Starter ericr23

    (@ericr23)

    Simple, as it turned out: I added the condition “(current_user_can(‘edit_posts’))” to where the plugin added draft posts to the search query.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Possible to enclose RSS feed posts in if statement?’ is closed to new replies.