At a guess (and I haven’t checked) I’d say that
bbp_get_forum_id()
works for a new topic, but returns a null when editing, hense your ‘==’ is never fulfilled.
Since you should have $topic_id set in either case, maybe try something like
$forum_id = bbp_get_topic_forum_id( $topic_id );
to get the forum or just use that if editing?
Have a play and see if that fixes.
Thanks, I got it figured out as far as text fields keeping content when editing.
I changed the start of my bbp_applications_fields to the following (in case anyone comes accross this thread):
function bbp_application_fields() {
$forum_id = bbp_get_forum_id();
$application_forum_id = 34;
$topic_id = bbp_get_topic_id();
$topic_edit_id = bbp_get_topic_forum_id( $topic_id );
if( $forum_id == $application_forum_id || $topic_edit_id == $application_forum_id ) {
My select fields still don’t retain their content when editing, but I suspect that’s due to some jQuery I’m using to show/hide certain options based on other select boxes.
**EDIT**
It looks like none of the select fields come back with their saved value, just whatever the starter value is. I’ll keep playing around with it.
One last follow up for anyone who comes across this later on.
For the select drop downs on the edit page, I decided to “cheat” with jQuery to make sure the correct value is still selected.
This is the code in my functions.php file that creates the select input:
$play_os = get_post_meta( $topic_id, 'bbp_app_character_playos', true);
echo '<br><label for="bbp_app_character_playos">Select Input Label</label><br>';
echo '<select id="bbp_app_character_playos" name="bbp_app_character_playos" data-value="' . $play_os . '">
<option value="Yes" class="os-yes">Yes</option>
<option value="No" class="os-no">No</option>
</select>';
I’m displaying the current value in the data-value attribute so I can use it in the jQuery below:
function appEditValues(){
var playOsVal = jQuery('.topic-edit #bbp_app_character_playos').attr('data-value');
if(playOsVal == "Yes"){
jQuery('.topic-edit #bbp_app_character_playos').find('.os-yes').attr('selected','selected');
} else if (playOsVal == "No"){
jQuery('.topic-edit #bbp_app_character_playos').find('.os-no').attr('selected','selected');
}
}
The jQuery code adds the “selected” attribute to the appropriate option on the edit page, which of course causes that value to be selected and save correctly again when you finish editing.
great – thanks for posting the solution, so many don’t and it helps anyone coming across this later on. 🙂