• Resolved Lineone

    (@lineone)


    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/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor ankitgadertcampcom

    (@ankitgadertcampcom)

    Hi,

    This question seems irrelevant to the plugin. You can use wordpress support forum for this question or you can ask this question on bbPress support forum.

    Thread Starter Lineone

    (@lineone)

    Thanks Ankit,

    I found the answer in:

    /bbpress-multi-image-uploader/includes/hooks/topic-hooks.php

    Use: bbp_new_topic_post_extras when saving a new topic.

    Use: bbp_edit_topic_post_extras when saving a topic after editing.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get attachment urls after saving topic’ is closed to new replies.