• Hi,
    please bare with me, I’m a newbie ?? I have set up a couple of custom post types (news, articles, etc) with custom taxonomies (language, country, etc). I would like to have the option for logged in users to have a way of choosing with checkboxes the post types and taxonomies they would like to appear in their post loop, and this choice to be saved, until they change it. It would be also good if they could subscribe via rss to this custom feed.
    Is this even possible? I have searched for days without luck.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Well, the posts returned in any query can be altered through the “pre_get_posts” action. All post queries go through this action, so you must limit what queries are altered. At least check is_main_query() and is_archive(). Further refinement may be necessary.

    To know how to alter the query would depend on how you collect user preferences. A form on the relevant page I suspect. The form can be added to the respective template. When you alter theme templates, you should create a child theme so your changes are protected during theme updates. Also alter the template to handle form submits and save the user preferences to user meta.

    Part of the pre_get_posts callback would be to get the user preferences in user meta and transform those to proper query args that are then set for the current query.

    As for RSS feeds, I’m not so sure how feasible it is. Users are not logged in when getting feeds, so WP cannot know whose preferences to use. If it did, you could customize the feed using pre_get_posts still, checking is_feed() instead of is_archive(). I suppose you could customize the feed somehow where the username is part of the feed request. See Customizing Feeds.

    Even if passing a user name through the feed request would work, it may not be a good idea. No password or login is required, so anyone knowing a user’s logon could learn their preferences. While such information isn’t particularly sensitive, it’s still personally identifiable data that should not be shared without express permission from the data owner.

Viewing 1 replies (of 1 total)
  • The topic ‘Save custom post query for user’ is closed to new replies.