WordPress.org

Ready to get started?Download WordPress

Forums

Automatically Create a post when uploading audio files (3 posts)

  1. hachimaki990
    Member
    Posted 1 year ago #

    I'm looking for a way to upload audio files to the media library and create a post automatically. Ideally when a user loads a audio file into the Media Library

    1. Go to Media library > upload media
    2. WordPress checks to see if its a audio file.
    3. If so create a post that contains the link to the audio file in the content of the post.

    I found this snippet of code that actually allows you to create posts when uploading images and attaches them them as a featured image. I figure the principle much the the same.

    add_action('add_attachment', 'create_post');
    function create_post( $attach_ID ) {
    
        $attachment = get_post( $attach_ID );
    
        $my_post_data = array(
                    'post_title' => $attachment->post_title,
                    'post_type' => 'posts',
                    'post_category' => array('audio-library'),
                    'post_status' => 'publish',
    		'post_content' => '<a href="Need Link Here">Click to Play</a>'
        );
        $post_id = wp_insert_post( $my_post_data );
    
       add_post_meta( $post_id, '_thumbnail_id', $attach_ID, true );
    
        return $attach_ID;
    }

    I'm not much of a coder and I can't seem to wrap my head around this. Ideally what I'm looking to do is turn wordpress into a audio library itself and allow back end users to upload audio files and have them display on the front-end as a post but without having to upload each audio file and create each post one by one. I got like 200 to start with (>.<)

    I figure wordpress has all the functionality already there I just need to get it working together. Even a plugin that can manage audio files in such a way would be wonderful but I have yet to find one.

    Thoughts?

    P.S. I working with WordPress 3.1.4 darn server only got PHP 4, working on getting that upgraded (pain in the butt).

  2. Dale R
    Member
    Posted 1 year ago #

    Hi,

    I'm looking to add the ability for a user to upload an audio file to my website, probably as a post.

    Did you resolve your issue?

    Does anyone know of a plugin that allows a website user to upload audi (wav and/or MP3 files?)
    Am I using the wrong vocabulary? Maybe its a short podcast I want the user to be able to upload...??

    Thanks

  3. hachimaki990
    Member
    Posted 1 year ago #

    I wasn't able to find the ideal solution as of yet. What I did do is more or less create my own plugin using "custom post types" and "custom fields" to create a pseudo-audiolibray.

    Thus, every time I create a post in the "custom post type" I attach a audio file to that post and place its file-path into a custom field.

    I then pass that file-path to a output in the custom-single.php template for that post-type. I would then use this Mini Audio Player do play the audio file.

    I still haven't figured out how to bulk upload yet.

Topic Closed

This topic has been closed to new replies.

About this Topic