I want insert details of topics into the database after the topic is saved. Which hook should I use so that the attachment url is available?
I am using code similar to this:
function add_news_after_topic_save( $post_id )
{
global $wpdb;
$args = array( 'post_type' => 'attachment', 'post_parent' => $post_id );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
$attached_url = get_the_attachment_link( $attachment->ID , false );
}
}
$message = 'New topic added in Forum_Name <img src="' . $attached_url . '" alt="" />';
$url = bbp_get_topic_permalink();
$matches = array('nid' => $nid);
$data = array('news' => '<a href=\''.$url.'\'>'.$message.'</a>');
$wpdb->update( "$wpdb->news", $data, $matches);
}
add_action("bbp_new_topic", "add_news_after_topic_save", 10, 4);
I have tried various different hooks but don’t seem to be able to retrieve the attachment urls successfully. Can you advise?
Thanks in advance
https://wordpress.org/plugins/bbpress-multi-image-uploader/