{"id":5406341,"date":"2014-10-20T21:14:31","date_gmt":"2014-10-20T21:14:31","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/set-front-page-with-php\/"},"modified":"2016-08-22T03:38:55","modified_gmt":"2016-08-22T03:38:55","slug":"set-front-page-with-php","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/set-front-page-with-php\/","title":{"rendered":"Set front page with php"},"content":{"rendered":"<p>Hi, everyone. I am trying to set a different page as front page, depending on the value of a counter-variable. I created a child theme and placed the following code in it. Unfortunately it&#8217;s not working and I am not particularly firm with php. Any help in getting it to work is greatly appreciated.<\/p>\n<p>&lt;?php<br \/>\n\/\/ Exit if accessed directly<br \/>\nif ( !defined(&#8216;ABSPATH&#8217;)) exit;<\/p>\n<p>\/* Add custom functions below *\/<\/p>\n<p>if (is_new_day() ):<br \/>\n$SignupCounter = 0;<\/p>\n<p>if (is_page( &#8216;confirmed-signup&#8217; ) ):<br \/>\n$SignupCounter++; <\/p>\n<p>if ($SignupCounter == 0) : {<br \/>\n\t$LP = get_page_by_path( &#8216;\/home-0&#8217; );<br \/>\n\tupdate_option( &#8216;page_on_front&#8217;, $LP-&gt;ID );<br \/>\n\tupdate_option( &#8216;show_on_front&#8217;, &#8216;page&#8217; );<br \/>\n}<\/p>\n<p> elseif ($SignupCounter == 1) : {<br \/>\n\t$LP = get_page_by_path( &#8216;\/home-1&#8217; );<br \/>\n\tupdate_option( &#8216;page_on_front&#8217;, $LP-&gt;ID );<br \/>\n\tupdate_option( &#8216;show_on_front&#8217;, &#8216;page&#8217; );<br \/>\n}<\/p>\n<p>elseif ($SignupCounter == 2) : {<br \/>\n\t$LP = get_page_by_path( &#8216;\/home-2&#8217; );<br \/>\n\tupdate_option( &#8216;page_on_front&#8217;, $LP-&gt;ID );<br \/>\n\tupdate_option( &#8216;show_on_front&#8217;, &#8216;page&#8217; );<br \/>\n}<\/p>\n<p>elseif ($SignupCounter == 3) : {<br \/>\n\t$LP = get_page_by_path( &#8216;\/home-3&#8217; );<br \/>\n\tupdate_option( &#8216;page_on_front&#8217;, $LP-&gt;ID );<br \/>\n\tupdate_option( &#8216;show_on_front&#8217;, &#8216;page&#8217; );<br \/>\n}<\/p>\n<p>elseif ($SignupCounter == 4) : {<br \/>\n\t$LP = get_page_by_path( &#8216;\/home-4&#8217; );<br \/>\n\tupdate_option( &#8216;page_on_front&#8217;, $LP-&gt;ID );<br \/>\n\tupdate_option( &#8216;show_on_front&#8217;, &#8216;page&#8217; );<br \/>\n}<\/p>\n<p>elseif ($SignupCounter &gt;= 5) : {<br \/>\n\t$LP = get_page_by_path( &#8216;\/home-5&#8217; );<br \/>\n\tupdate_option( &#8216;page_on_front&#8217;, $LP-&gt;ID );<br \/>\n\tupdate_option( &#8216;show_on_front&#8217;, &#8216;page&#8217; );<br \/>\n}<\/p>\n<p>?&gt;<\/p>\n","protected":false},"template":"","class_list":["post-5406341","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5406341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5406341\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5406341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}