Skip to main content
26 events
when toggle format what by license comment
Nov 27, 2020 at 7:54 vote accept freedom667
Nov 23, 2020 at 12:17 comment added Tom J Nowell So you haven't checked the actual value? That does not mean the value is null, it could mean the selected part is incorrect. I asked in my last comment several important questions about how the code is executed and where it's located but you did not answer any of those questions. Can you answer them? It is super important. What does the rest of the code in your question look like? How is it being ran?
Nov 23, 2020 at 10:30 comment added freedom667 gives me null because all select input output is default again after saved.
Nov 23, 2020 at 9:09 comment added Tom J Nowell @freedom667 quick question, your code example in your original question, how is it being executed? It's missing the context such as what hook it runs on, what happens to the $elements array, etc. Also how are you testing that it's null?
Nov 23, 2020 at 7:30 comment added freedom667 did not work. I saved but gives me null
Nov 20, 2020 at 12:37 comment added Tom J Nowell @freedom667 I hadn't tested it out, but it's about 99% there, I just spotted a silly typo I made and updated it
Nov 20, 2020 at 12:36 history edited Tom J Nowell CC BY-SA 4.0
deleted 3 characters in body
Nov 20, 2020 at 12:10 comment added freedom667 I will try your code. if it works, I will accept your answer
Nov 20, 2020 at 12:00 history edited Tom J Nowell CC BY-SA 4.0
added 2583 characters in body
Nov 20, 2020 at 11:49 comment added Tom J Nowell Fundamentally, these are all separate fields, that need separate HTML, separate handling, separate saving. You cannot share things to save time, they need to be treated as unique individual fields. I'm including a limited example in my answer shortly
Nov 20, 2020 at 11:36 comment added Tom J Nowell Yes, otherwise the HTML tag would be the same for all select inputs, likewise it looks like you haven't spotted my comment on using the selected function, check the third parameter. To be able to help you debug the new code I'll need to be able to see it
Nov 20, 2020 at 7:56 comment added freedom667 I thought I did it. but as I said, just get_the_author_meta works. I don't know why. I wrote echo for control, because I wondered the output. gives me like this. two selected='selected'twelve selected='selected'nine selected='selected'two selected='selected'twelve selected='selected'nine selected='selected' the first text is two, this is last element but why is there I don't know
Nov 20, 2020 at 6:16 comment added freedom667 I already understood, my question is, the html tags will be in loop?
Nov 19, 2020 at 22:03 comment added Tom J Nowell Your use of the $menu variable outside the loop does not work, you should not use a $menu variable, it is causing problems. Each select must be unique, they cannot be the same, they have to be different. There is no avoiding this
Nov 19, 2020 at 21:02 comment added freedom667 but then, I cannot put $menu variable because input should be in foreach. input names will be level ids. $user_level collecting level ids
Nov 19, 2020 at 19:00 comment added Tom J Nowell correct, in my answer I name it <select name='time-selector-' . $user_level . '....
Nov 19, 2020 at 17:48 comment added freedom667 the I should assign a variable to input name and it will give different name in loop, right? for example '<input name="'. $user_level ."'>, right?
Nov 19, 2020 at 11:27 comment added Tom J Nowell I saw, you already have a list of the levels in an array named $user_levels, just use a loop. The names, user meta key, and IDs must be unique, there is no getting around that, it is a hard requirement and unavoidable. They must be unique, they cannot be the same, you cannot create the HTML for the select once then reuse it for every single user level because then they all have the same HTML/names/IDs, it has to be done inside the loop
Nov 19, 2020 at 11:13 comment added freedom667 but the levels can be 4,3 or 1. So, the levels are not fixed. one user has 5 levels, another user has 2 levels. it works this way.
Nov 19, 2020 at 10:35 history edited Tom J Nowell CC BY-SA 4.0
added 53 characters in body
Nov 19, 2020 at 10:29 comment added Tom J Nowell @freedom667 I can't see the code changes you've made to use get_user_meta so I don't know how to help or what went wrong. TLDR all your inputs have the same name, and you only store the value once. If you have 5 user levels, then you need 5 inputs, 5 input names, 5 IDs, 5 meta keys, not 1
Nov 19, 2020 at 10:14 comment added freedom667 nothing changed, also get_user_meta returns null
Nov 19, 2020 at 9:44 history edited Tom J Nowell CC BY-SA 4.0
deleted 905 characters in body
Nov 19, 2020 at 9:38 comment added Tom J Nowell @freedom667 please edit your question to include that information, it significantly changes the meaning of your question
Nov 19, 2020 at 7:48 comment added freedom667 my select menu is not multiple. it has not to be multiple. $menu variable will next to each level. let me show you with some pictures. Also get_user_meta not working. imgur.com/GQ25QrA - imgur.com/q2O4XUR maybe I could explain with pictures.
Nov 18, 2020 at 20:45 history answered Tom J Nowell CC BY-SA 4.0