最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

customization - Get site ID from attachment url?

matteradmin6PV0评论

I created a function which gets the metadata video length from the selected attachment. I use this together with a plugin called multisite-global-media which lets me share media from a site to all other sites in the multisite network. But selecting a video from this media site will break my function, as I am not able to pull the metadata from attached media from the other site except if I use the switch_to_blog function.

But I need to determine if the selected media is from the current site or from the media site.

This is what I am working on:

switch_to_blog($attachment_site);

$attachment_id = attachment_url_to_postid( $_POST[ 'background-video' ] );
$video_meta = get_post_meta( $attachment_id , '_wp_attachment_metadata', true ); 

restore_current_blog();

if( isset( $_POST[ 'background-video' ] ) && $video_meta['length'] >= 1 ) {
    update_post_meta( $post_id, 'slide_duration', $video_meta['length'] );
}

What I need to do is to get the $attachment_site somehow.

Any idea how?

EDIT:

if( isset( $_POST[ 'background-video' ] ) ) {
    update_post_meta( $post_id, 'background-video', $_POST[ 'background-video' ] );
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far