Multisite – Get current post id

try this $sites = get_sites(); global $switched; /** @var WP_Site $site */ foreach ($sites as $site) { if ( $site->archived || $site->spam || $site->deleted ) { continue; } switch_to_blog( $site->blog_id ); $all_posts = get_posts(‘category=-3&numberposts=6&orderby=post_name&order=DSC’); ?> <ul> <?php foreach($all_posts as $post) : setup_postdata($post);?> <li> <a href=”https://wordpress.stackexchange.com/questions/354427/<?php echo get_page_link($post->ID); ?>” title=”<?php echo $post->post_title; ?>”><?php echo $post->post_title; ?></a> … Read more

restore_current_blog required after switch_to_blog, if I use that in a function?

switch_to_blog changes values of global variables (as you can see here: https://core.trac.wordpress.org/browser/tags/5.0.3/src/wp-includes/ms-blogs.php#L801). It doesn’t matter if you call it in function or not – these variables will get changed. So yes – you always have to call restore_current_blog when you’ve done all you wanted with the switched blog. Otherwise these variables will stay changed (so … Read more

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?

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 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)