• Resolved hshah

    (@hshah)


    I’ve got a function that will rename files based on the post_title and post_author, but when images are being uploaded from the frontend, the post doesn’t exist until after it is saved.

    I tried to use the Rename on Post Save option but that doesn’t seem to do anything ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter hshah

    (@hshah)

    Sorted lol ??

    function photos_rename($album_id)
    {
    	$photo_posts = get_posts( array( 'numberposts' => -1, 'post_type' => 'attachment', 'post_parent' => $album_id, 'suppress_filters' => false ));
    	foreach( $photo_posts as $photo_post ){
    		mfrh_rename( $photo_post->ID );
        }	
    }
    Plugin Author Jordy Meow

    (@tigroumeow)

    Exactly the way you should do it, yes ?? It’s mentioned in my FAQ, but maybe that’s how you learn about it.

    Wow! I emailed Jordy few days ago after I purchased the Pro version, this is a bit similar to what I was looking for, only I wanted to prepend the domain name and author name at the beginning of the filename.
    Basically something like this:
    domain-name-author-post-title-date.jpg

    • This reply was modified 5 years, 2 months ago by Fanaticweb.
    Thread Starter hshah

    (@hshah)

    @tigroumeow Yep, that’s exactly where I figured it out from and just posted it here for the benefit of others who may be looking for something similar.

    I have another function which defines the new name, but I now want to define different names for other types of uploads. The naming structure for what I mentioned earlier completely ignored the existing name and used author and parent post title because that was for user specific photo albums. For images uploaded to events, I want to use just the parent post title.

    How would I do that?

    Plugin Author Jordy Meow

    (@tigroumeow)

    I can’t write the full code here, that would take me some time, but you would need a condition of the post type either events or albums), and then set the filename you’d like depending on this. You will need to look for the post to which the image is attached, a part of the response is probably here: https://wordpress.stackexchange.com/questions/113516/associate-an-existing-image-with-a-post.

    Thread Starter hshah

    (@hshah)

    @tigroumeow Sorry, I think my question was a little silly. I already have this:

    add_filter('mfrh_new_filename', 'my_filter_filename', 10, 3);
    function my_filter_filename($new, $old, $post) {

    So, added if else to the part where I’m already checking the post type etc is stupidly easy lol

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Rename on Upload but AFTER Post Save’ is closed to new replies.