@robin-w, here is my code for the custom fields. You will see where arguments and names match the variables being passed from javascript. This code was placed in a separate file as an additional plugin:
add_action ( 'bbp_theme_before_topic_form_content', 'bbp_extra_fields');
function bbp_extra_fields() {
//This is where the cover will go, from google book search
$value = get_post_meta( bbp_get_topic_id(), 'bookCover', true);
echo '<label for="bookCover">Book Cover URL</label><br>';
echo "<p><textarea style='width: 250px; height: 50px' name='bookCover' value='".$value."'></textarea></p>";
//Input field for the Author
$value = get_post_meta( bbp_get_topic_id(), 'bookAuthor', true);
echo '<label for="bookAuthor">Author</label><br>';
echo "<p><input type='text' name='bookAuthor' value='".$value."'></p>";
$value = get_post_meta( bbp_get_topic_id(), 'bookPublished', true);
echo '<label for="bookPublished">Published</label><br>';
echo "<p><input type='text' name='bookPublished' value='".$value."'></p>";
//Input field for the number of pages in print
$value = get_post_meta( bbp_get_topic_id(), 'bookPages', true);
echo '<label for="bookPages">Pages</label><br>';
echo "<p><input type='text' name='bookPages' value='".$value."'></p>";
//Input field for the Publisher that corresponds to the Published data
$value = get_post_meta( bbp_get_topic_id(), 'bookPublisher', true);
echo '<label for="bookPublisher">Publisher</label><br>';
echo "<p><input type='text' name='bookPublisher' value='".$value."'></p>";
//Input field for the ISBN
$value = get_post_meta( bbp_get_topic_id(), 'bookISBN', true);
echo '<label for="bookISBN">ISBN</label><br>';
// echo "<p><input type='number' name='bookISBN' value='".$value."'></p>";
echo "<p><input type='text' name='bookISBN' value='".$value."'></p>";
}
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['bookCover']!='')
update_post_meta( $topic_id, 'bookCover', $_POST['bookCover'] );
if (isset($_POST) && $_POST['bookAuthor']!='')
update_post_meta( $topic_id, 'bookAuthor', $_POST['bookAuthor'] );
if (isset($_POST) && $_POST['bookPublished']!='')
update_post_meta( $topic_id, 'bookPublished', $_POST['bookPublished'] );
// if (isset($_POST) && $_POST['bookDescription']!='')
// update_post_meta( $topic_id, 'bookDescription', $_POST['bookDescription'] );
if (isset($_POST) && $_POST['bookPages']!='')
update_post_meta( $topic_id, 'bookPages', $_POST['bookPages'] );
if (isset($_POST) && $_POST['bookPublisher']!='')
update_post_meta( $topic_id, 'bookPublisher', $_POST['bookPublisher'] );
if (isset($_POST) && $_POST['bookISBN']!='')
update_post_meta( $topic_id, 'bookISBN', $_POST['bookISBN'] );
}
add_action('bbp_template_before_replies_loop', 'bbp_show_extra_fields');
//add_action('bbp_template_before_main_content', 'bbp_show_extra_fields');
function bbp_show_extra_fields() {
$topic_id = bbp_get_topic_id();
$valuec = get_post_meta( $topic_id, 'bookCover', true);
$value1 = get_post_meta( $topic_id, 'bookAuthor', true);
$value2 = get_post_meta( $topic_id, 'bookPublished', true);
// $value3 = get_post_meta( $topic_id, 'bookDescription', true);
$value4 = get_post_meta( $topic_id, 'bookPages', true);
$value5 = get_post_meta( $topic_id, 'bookPublisher', true);
$value6 = get_post_meta( $topic_id, 'bookISBN', true);
//Below is the table format for displaying a book. Might consider changing this
//to a form??? html header???
?>
<table style="width:900px">
<col width="100">
<col width="265">
<col width="535">
<tr>
<td style="vertical-align:top">
<img src=<?php printf(rawurldecode($valuec))?> />
</td>
<td style="vertical-align:top">
<strong><p style="font-size: 14px";>Author: </strong><?php printf( $value1); ?> </p>
<strong><p style="font-size: 14px";>Published: </strong><?php printf( $value2); ?></p>
<strong><p style="font-size: 14px";>Page(s): </strong><?php printf( $value4); ?></p>
<strong><p style="font-size: 14px";>Publisher: </strong><?php printf( $value5); ?></p>
<strong><p style="font-size: 14px";>ISBN: </strong><?php printf( $value6); ?></p><br>
<strong><div style="font-size: 14px";>Description </strong></div>
</td>
</tr>
</table>
<?php
}
It would probably also be instructive for me to include the review-meta.php file that is called by javascript, so here is that code as well:
if ( isset( $_POST['cover'] )) {
$cover = $_POST['cover'];
}
if ( isset( $_POST['coverSmall'] )) {
$coverSmall = $_POST['coverSmall'];
}
if ( isset( $_POST['title'] )) {
$title = $_POST['title'];
}
if ( isset( $_POST['author'] )) {
$author = $_POST['author'];
}
if ( isset( $_POST['published'] )) {
$published = $_POST['published'];
}
if ( isset( $_POST['description'] )) {
$description = $_POST['description'];
}
if ( isset( $_POST['pages'] )) {
$pages = $_POST['pages'];
}
if ( isset( $_POST['publisher'] )) {
$publisher = $_POST['publisher'];
}
if ( isset( $_POST['ISBN'] )) {
$ISBN = $_POST['ISBN'];
}
$r=array("cover"=>$cover,"coverSmall"=>$coverSmall,"title"=>$title,"author"=>$author,"published"=>$published,
"description"=>$description,"pages"=>$pages,"publisher"=>$publisher,"ISBN"=>$ISBN);
print(json_encode($r));