Is it possible to edit an option such as the page_on_front setting in a local scope, without updating the option in the database? For instance, I am attempting to serve a different homepage to logged in users, and via this solution it is suggesting that I use is_user_logged_in() and then call update_option( 'page_on_front', $page->ID ) to whichever id I want based on that status. However, the update_option() function actually updates the option in wp_options with every page load, which seems like unnecessary overhead to me. Is there a way to just edit whichever variable or object is holding that value when someone hits a page?

  • 1
    You might be able to use the pre_get_posts filter - check if it's the main query and is for the homepage; if the user is logged in change the query to grab a different post ID than what's currently set. – WebElaine Oct 24 '17 at 20:57
  • @WebElaine Thanks. Worse case I can also just use is_logged_in() in a custom homepage template and run different a custom wp_query() based on that, but I was still curious if there were a way to just set the homepage. I tried doing it with: $objcache = $GLOBALS['wp_object_cache']; $objcache->page_on_front = "11"; But it seemed to have no effect. – Michael VanDeMar Oct 24 '17 at 21:21
  • Maybe try wp_cache_replace - codex.wordpress.org/Class_Reference/WP_Object_Cache - I would just be concerned and want to verify that a change would not get cached for everyone viewing the site at the time, just the current user. – WebElaine Oct 25 '17 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.