logo
down
shadow

File path without domain name from wp_get_attachment_url()


File path without domain name from wp_get_attachment_url()

By : user2956617
Date : November 22 2020, 10:56 AM
this one helps. You can really easily explode it by / and then take the part with index 3. Example
code :
$url = wp_get_attachment_url(id); //id is file's id
$urllocal = explode(site_url(), $url)[1]; //output local path


Share : facebook icon twitter icon
RegEx to get path of file, without domain

RegEx to get path of file, without domain


By : user1240535
Date : March 29 2020, 07:55 AM
I wish this helpful for you construct a URI object from it and one of the properties of it will have what you want.
why when I try to insert an image attachment along with a post does wp_get_attachment_url give me a very wrong file path

why when I try to insert an image attachment along with a post does wp_get_attachment_url give me a very wrong file path


By : Jevalo nahi ajun mi
Date : March 29 2020, 07:55 AM
it helps some times It turns out I was barking up the wrong (or at least a slightly different) tree by using wp_insert_attachment. media_sideload_image managed to pull attachments from other blogs on the same multisite install, copy them to the aggregating blog's uploads directory, and generate thumbnails, while wp_insert_attachment was doing what it was supposed to, which just happened to not be what I wanted. I realize that this is just a slight variation on other fairly well explained uses of similar functionality, but I figured I'd post my solution here in case anyone happens to have more success applying this particular combination of solutions.
I still get the sense that I'm not doing this in the most efficient way, but it's working for now:
code :
function switch_and_insert($srcblog, $targetcat, $fromcat) {
  switch_to_blog($srcblog);
  $args  = array( 'numberposts' => 1, 'category_name' => $fromcat);
  $flastpost = get_posts( $args );
  foreach($flastpost as $post) : setup_postdata($post);
    $extrapost = array();
    $extrapost['post_title'] = get_the_title($post);
    $extrapost['post_content'] = get_the_post_thumbnail();
    $extrapost['comment_status'] = 'closed';
    $extrapost['post_status'] = 'publish';
    $extrapost['post_date'] = get_the_date( $d = 'Y-m-d H:i:s');
    $extrapost['post_category'] = array($targetcat);
    $oldid = get_the_ID();
    if ( has_post_thumbnail($oldid)) {
        $filename = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    }
    else $filename = $forchomper; // URL of backup image
    switch_to_blog($aggregator_blog_id);
        $post_id = wp_insert_post($extrapost);
        $wp_filetype = wp_check_filetype(basename($filename), null );
        $wp_upload_dir = wp_upload_dir();
        $attachment = array(
            'guid' => _wp_relative_upload_path( $filename ), 
            'post_mime_type' => $wp_filetype['type'],
            'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
            'post_content' => '',
            'post_status' => 'inherit'
        );
        require_once(ABSPATH . "wp-admin" . '/includes/media.php');
        require_once(ABSPATH . "wp-admin" . '/includes/image.php');
        require_once(ABSPATH . "wp-admin" . '/includes/file.php');
        $sideloaded = media_sideload_image($filename, $post_id);
        $attachments = get_children($post_id);
        foreach ( $attachments as $attachment_id => $attachment );
        set_post_thumbnail($post_id, $attachment_id);
    restore_current_blog();
    wp_reset_postdata();
  endforeach;
  restore_current_blog();
}
htaccess multiple domain, force specific domain and its paths to www and exclude a path but redirect excluded path

htaccess multiple domain, force specific domain and its paths to www and exclude a path but redirect excluded path


By : Toni Reyes
Date : March 29 2020, 07:55 AM
Hope this helps to @Christophe for helping me find a solution. You can check out our conversation as comments within Christophe's answer. The solution was to repeat the HTTP_HOST condition again. So in the end my .htaccess looked like this.
code :
RewriteEngine on
RewriteCond %{HTTP_host} ^en.one$     
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin     
RewriteRule ^(.*) http://www.en.one/$1 [R=301,L]
RewriteCond %{HTTP_host} ^en.one$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/admin         
RewriteRule ^(.*) http://www.en.me/ [R=301,L]
.htaccess - redirect to same path from domain A to domain B - polish letters in domain name

.htaccess - redirect to same path from domain A to domain B - polish letters in domain name


By : user2807230
Date : March 29 2020, 07:55 AM
will be helpful for those in need How I can redirect using .htaccess file from domain: testÓwka.net to domain testOwka.net with saving URL path? , Try modify your rewrite to:
code :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?xn--testwka-o0a\.net [NC]
RewriteRule (.*) http://testowka.net/$1 [R=301,L]
NodeJs Server set on port XXXX, relative path GET domain:XXXX/path instead of domain/path

NodeJs Server set on port XXXX, relative path GET domain:XXXX/path instead of domain/path


By : João Filipe
Date : March 29 2020, 07:55 AM
will be helpful for those in need I'm setting up a server on port XXXX which contains multiple route rendering ejs. In these ejs files I try to access pictures with relative path (basically "../public/images/images.png") but it says that i'm trying to access domain:port/path instead of domain/path. , Try using absolute path instead relative path
code :
change 
../public/images/images.png
to
/images/images.png           // because you have added line
 app.use(express.static(path.join(__dirname, '/public'))); 
which directly refer to public folder for any of the static files.`
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org