• How can I get and then check this PAGE ID which is a post id due to my permalink setup,
    I need to do an IF ELSE statement depending on the page id,

    I have tfe code as follows but only the 1st if works when i am working on the 2nd page it doesnt go into the 2bd if statement.
    Its 2 registration forms.

    add_action( ‘user_register’, ‘add_new_acount_fields_to_metadata’, 10, 1);
    function add_new_acount_fields_to_metadata($user_id){
    global $page_id;
    $page_id = get_the_ID();
    if($page_id = 208191){
    update_user_meta($user_id, ‘Count_reg_schoolhopper’, 0);
    update_user_meta($user_id, ‘Count_hist_per_schoolhopper’, 0);
    update_user_meta($user_id, ‘Count_view_per_area’, 0);
    update_user_meta($user_id, ‘Cost_model_user_chose’, 1);
    }
    Else
    if($page_id = 210421){
    update_user_meta($user_id, ‘Count_reg_schoolhopper’, 0);
    update_user_meta($user_id, ‘Count_hist_per_schoolhopper’, 0);
    update_user_meta($user_id, ‘Count_view_per_area’, 0);
    update_user_meta($user_id, ‘Cost_model_user_chose’, 2);

    }

    }

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hi @judyoos

    I’m not quite sure I understand what you’re trying to accomplish.
    You’re using the “user_register” action-hook – but how are you using it?
    Is the user using a front-end form? Or do you register them through the backend?

    I would 100% recommend using AJAX for this purpose.
    That way you can send the page_id, and make your if/else statement.

    Best regards
    Aris Kuckovic

    Thread Starter judyoos

    (@judyoos)

    I have 2 registration Pages for a user to register. due to the fact that I have 2 price plans to use the system. On registration i need to create 4 user field in the user meta data to use for logic in the system. Hence the update statements. all i now want to add is if the user user registration page 1 then do this set of updates else if it uses the registration page 2 then use the 2nd updates. thats all. so th user_register gets fired when a user register on the system.

    Thread Starter judyoos

    (@judyoos)

    it worked 100% till I added the page check. prior I only had one registration page.

    Thread Starter judyoos

    (@judyoos)

    Front end form using theme my login plugin. The 1st if works…..

    Hi @judyoos

    Okay, I get that part now.
    Are the signup fields created with a plugin?
    Or did you code them yourself.

    Ah okay, I see your replies now.
    I don’t know the “Theme my login” plugin.
    But you can’t get the page_id() the way you’re trying to accomplish it – because the code (i suppose it’s in functions.php) does not know what page_id() the action is called from – so you’ll have to check this in one way or another. That’s why I suggested AJAX.

    Are you any familiar with AJAX?

    • This reply was modified 4 years, 10 months ago by kuckovic.
    Thread Starter judyoos

    (@judyoos)

    Are you talking about the fields on the registration form?
    If so they were created by the plugin “Theme-my-login”.

    The user meta fields I created via the update statements in the code I showed you.

    • This reply was modified 4 years, 10 months ago by judyoos.
    Thread Starter judyoos

    (@judyoos)

    No I am not familiar with AJAX.

    Thread Starter judyoos

    (@judyoos)

    Jip I seems that now…the code is in a Code-snippets plugin. so I need to find another way to resolve the issue around the page id.

    Jip I seems that now…the code is in a Code-snippets plugin. so I need to find another way to resolve the issue around the page id.

    I think so too, yes.
    And I would suggest AJAX to accomplish this.

    Thread Starter judyoos

    (@judyoos)

    I will google it thank a lot

    Hi @judyoos

    Here’s an example on how to use AJAX with forms: https://webprogramo.com/how-to-create-an-ajax-form-in-wordpress/1156/

    Let me know if you need further assistance ??

    Best regards
    Aris Kuckovic

    Thread Starter judyoos

    (@judyoos)

    Thanks so much I will study it.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘PAGE ID – get it and use it issue’ is closed to new replies.