Re: Add custom metadata to forum topics for sorting purposes
The ‘bp_after_group_forum_post_new’ hook is used to add data to the template, rather than to process the data. So instead of manually editing the forum.php template, you would do something like:
`cg_add_post_metacat_html() {
echo ”;
}
add_action( ‘bp_after_group_forum_post_new’, ‘cg_add_post_metacat_html’ );`
To process the post data, you would do something like:
`function cg_postcatagory( $post_id = false ) {
if ( empty( $post_id ) || empty( $_POST ) )
return false;
$post_id = (int) $post_id;
$postmeta = $_POST;
$cg_newmeta = ( cg_newmeta( $post_id, $postmeta ) ) ? true : false;
return $cg_newmeta;
}
add_action( ‘bp_forums_new_post’, ‘cg_postcatagory’ );`
You’ll also need to adjust your newmeta function to something like:
`function cg_newmeta( $id, $postcat ) {
global $catagory, $wpdb, $bbdb;
do_action( ‘bbpress_init’ );
$wpdb->query( $wpdb->prepare( “INSERT INTO $bbdb->meta ( meta_id, object_type, object_id, meta_key, meta_value ) VALUES (%d, %s, %d, %s, %s )”, $catagory->meta_id, ‘bb_cgcat’, $id, ‘cg_catagory’, $postcat ) );
}`