1. Go to this page and download the library: Download survos/wordpress-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
survos / wordpress-bundle example snippets
use Survos\WordpressBundle\Client\WordpressClientInterface;
final readonly class ArticleImporter
{
public function __construct(
private WordpressClientInterface $wp, // the default site
#[Target('kpa')] private WordpressClientInterface $kpa, // a named one
) {}
public function import(): void
{
foreach ($this->wp->posts()->iterateDto(['status' => 'publish']) as $post) {
// $post is a WpPost; $post->raw still holds every ACF/plugin field
$this->store($post->id, $post->title, $post->content);
}
}
}
$client = $registry->get($siteName); // null → the default site
$registry->names(); // ['ff', 'kpa']
$client->resource('songs'); // a custom post type
$client->resource('options', 'acf/v3'); // a plugin's own namespace
$attachment = $client->media()->upload('/path/to/barn.jpg', [
'alt_text' => 'A barn in Rappahannock County',
'post' => $postId,
]);
// or, for bytes already in memory
$client->media()->uploadContents('barn.jpg', $bytes, 'image/jpeg');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.