I use the WordPress plugin "bbpress" to create a bulletin board.
I’m trying to add a file (image) upload function, but I can’t quite achieve it.
I expect to give the URL "example.com/wp-content/uploads/〇〇" at the location where the file is saved, But I can’t .
I would like you to correct my code.Thank you.
add_action ( 'bbp_theme_before_topic_form_content', 'bbp_extra_fields');
function bbp_extra_fields() {
$value11 = get_post_meta( bbp_get_topic_id(), 'bbp_extra_field2', true);
echo '<label for="bbp_extra_field2">pic</label><br>';
echo "<input type='file' name='bbp_extra_field2' accept='.jpg,.jpeg,.png,.gif' value='".$value11."'>";
}
add_action ( 'bbp_new_topic', 'bbp_save_extra_fields', 10, 1 );
add_action ( 'bbp_edit_topic', 'bbp_save_extra_fields', 10, 1 );
function bbp_save_extra_fields($topic_id=0) {
if (isset($_POST) && $_POST['bbp_extra_field2']!='')
update_post_meta( $topic_id, 'bbp_extra_field2',$_POST['bbp_extra_field2'] );
}
add_action('bbp_template_before_replies_loop', 'bbp_show_extra_fields');
function bbp_show_extra_fields() {
$topic_id = bbp_get_topic_id();
$value2 = get_post_meta( $topic_id, 'bbp_extra_field2', true);
echo "pic: ".$value2."<br>";
echo "picture:".;
echo'<img src="<?php wp_get_attachment_url( $id ); ?>'.$value2.'.jpg"alt="">';
}