When using function like wp_insert_post()
It will work on the currently active blog, meaning that if you are on a blog in your network with blog_id of 2 the the post you insert using wp_insert_post()
will be inserted to that blog.
Now if you want to insert the post to a specific blog you can use switch_to_blog()
function which will tell WordPress that “the current blog is” so you can use wp_insert_post()
to insert to that specific blog.
Then to tell WordPress that what is the real current blog you can use restore_current_blog()
so:
switch_to_blog($wanted_blog_ID);
...
...
your wp_insert_post() stuff
...
...
restore_current_blog();
take a look at WPMU Functions to understand more about the available functions in a network.
Related Posts:
- WP_INSERT_POST issue on WordPress Multisite
- Using wp_insert_post with WP Network in a cron script
- switch_to_blog($blog_id); still writing to main blog
- Manually insert post into MULTISITE database: Need to specify the TABLE
- Create site programmatically for WPMU
- WordPress Multisite allow site admin to add user without email confirmation
- Using one media library for a multisite network with WordPress 3.5 media library
- Troubleshooting a Network site displaying a blank page [closed]
- Add new column to sites page
- Wildcard subdomain for the same site
- Is there a filter to define the OG image on a given post?
- WordPress Multisite with NGINX, subfolders, and FROM a subfolder
- How to consolidate all sitemaps in a multisite network?
- Run a function when a new site is created in WordPress Multisite
- Multisite installation combining subdomains and subdirectories
- Can’t add user to blog on registration (Multisite)
- Sub-directory blog on a sub-domain WordPress network site
- Customizing Deleted/Archived blogs warning pages
- SQL Query to Get list of all users along with their blogs
- Synchronizing Two WordPress Sites Content
- Multisite Independent User Base
- Sharing Header Components Across Multisite
- Why is my multisite installation not showing all the available sites?
- Issue converting single site to multi-site – blogs.dir folder not created
- Logout issue with new Domain on WP Multisite
- PHP Notices appear when browsing any page in admin, but only for child theme, using code from WP Codex
- What is the most efficient way to have two “blogs” on one site?
- Preview posts returns 404
- How can I have multiple URLs pointing to single WordPress installation?
- How to exclude a directory from WordPress permalinks in a Multisite environment?
- Redirect subdomain homepage to domain specific page in wordpress multisite
- Make WordPress Search for Both Main Domain and Subdomain
- Create a network of blogs with WordPress 3
- Multisite new sites not found(404), main site still works [closed]
- create new site subsite in wordpress multisite by subscriber user instead of network admin
- Retrieving data from specific multisite blog
- Error 404 on Network Admin and others
- Retrieving multisite blog IDs, somehow failing to foreach them properly
- Get just subdirectory name from a multisite URL
- Why my deleted url is redirecting to random post?
- Reset a site in multisite
- Multisite – 404 when accessing sub-sites
- Redirect Site Geologically
- WordPress Network admin options page: how to store options and where will they be stored?
- How to use a Wildcard SSL with WordPress Network?
- Migrating wordpress multisite and domain mapping plugin
- WordPress Multisite – Can 2 domains share a database of users?
- Wrong filepaths and admin page infinite reload after migrating to aws bitnami
- Multisite not using subdomains as hostname in from address when sending emails
- Cookie signed verification failed – wp-saving-post
- What is the way to share data between sites in a multisite
- Do I need a Multisite? [closed]
- Error: reassigning content to a different user is not supported on multisite
- Run additional service on domain with WordPress Multisite?
- Development of new theme and rollout on multisite
- Update configured themes
- metaboxes disappear on saved pages
- User registration on two sites in same multisite
- Multiple subsites in a single wordpress installation
- 404 on page 2 multisite
- How many databases do I need?
- How to sync roles across Multisite?
- How can I append blog_id to … echo [functions-defined-constant]?
- Multisite Subdirectory Site Dashboard redirect loop
- WordPress Multisites or Multiple WP Single sites?
- Is it possible to disable html code error auto fixing feature by wordpress 4.9.1?
- WordPress Multisite Add User
- LimitInternalRecursion error
- Some permalinks are not working and show 404
- Should I use Multi Site to achieve different designs for different sections?
- WP MS: How to query over the network
- unable to access network admin of a blog
- User registration is currently not allowed
- $_SERVER[‘SERVER_NAME’] in WP_SITEURL
- WPMU on MySQL limited to 1GB of space?
- WordPress Multisite Permalinks on mapped domain = server 404 error
- Sites network with sub-folders
- Set my own password when registering a multisite user or site
- Efficient way to fetch all archived WPMS blogs
- WP-Cli Error When Mapping Multisite Subdomain
- Setup another new subdomain root on top of multisite configuration
- WordPress keeps deleting user account for multisite after loggin out i need your help please?
- Change main site / network admin site?
- Serve theme and plugins assets from correct domain on multi-domain multisite
- Themes are visible in Network, but invisible in sites
- logging out with/without confirmation – single site, multisite
- Multisite different domains mapping error on GGS
- Multisite – each site with it’s own set of users
- WordPress Multisite wp-admin/ redirect loop but adding index.php works fine
- Can WP multisite manage multiple ccTLDs
- Should i use multisite for my business?
- WordPress Network with SSL for multiple domains
- Nginx rules for subdomain multisite install (Bedrock)
- WordPress Multisite redirect loop
- How to Create WPMu New User?
- Is it possible to create a login for restricted visibility?
- WordPress Multisite Subsite WP admin not working
- multi-language multi-site with REST API
- How to make Multisite global login that redirects to correct subsite after login
- Multiple WordPress sites on one hosting [closed]