php - Multiple Page ids in wordpress function -
I have a WordPress function that redirects users to login while trying to view a certain page and that Moves to the page, log in.
The function works fine when I only enter a page ID
When I should redirect the url to log on to any of the page pages, The function stops working.
Please solve how I can help it.
add_action ('template_redirect', 'wpmy_check_if_logged_in'); Function wpmy_check_if_logged_in () {$ pageid = array (22 9, 1589, 1031); If (! Is_user_logged_in () and is_page ($ page ID)) {$ url = wp_login_url (get_permalink ($ pageide)); Wp_redirect ($ url); Go out; Instead}}
Call is_page (frequently with an ID), I just take ID global $ post object and see whether it's in your array:
add_action ( 'template_redirect', 'wpmy_check_if_logged_in'); Function wpmy_check_if_logged_in () {$ pageid = array (22 9, 1589, 1031); If (! Is_user_logged_in () and is_page ()) {global $ post; If (in_array ($ post-> ID, $ pagrid)) {$ url = wp_login_url (get_permalink ($ post-> ID)); Wp_redirect ($ url); Go out; }}}
Comments
Post a Comment