Skip to main content

Media Import with a given Name Overwrite media matching post title using WP CLI's media import command

I am trying to overwrite a media post using the WordPress CLI.

The wp post create --post_type=attachment command can create an empty media item, unable to be filled withbut cannot attach an image file through WP-CLI,WP-CLI. This is only possible through the GUI or other WP PHPWP PHP Functions (thus creating. The CLI command creates a "corrupt", media post. Is it better-to-avoid use from a WP-CLI user to avoid using this method?)

ByOn the other sidehand, the wp media import $filename docommand does not include (according the Documentation) fields like the --post_name,--post_date among others "post"sand other post fields, thus requiring a following. This method then requires running wp post update $id_media for setting themthese fields once the post is created.

Hence, it is not possible tofor wp media import $filename to overwrite a Media image with a givenpost that matches on --post_name -WP. If you try this, WP actually just createcreates a duplicatedduplicate media object, with a new regenerated --post_name-, thus all. This means the wp post exist and wp post delete process must be done "manually"manually as a part of this process.

Am I true with these observationsIs my thinking correct?

Media Import with a given Name

The wp post create --post_type=attachment command can create an empty media, unable to be filled with an image through WP-CLI, only through the GUI or other WP PHP Functions (thus creating a "corrupt", better-to-avoid use from a WP-CLI user?)

By other side, the wp media import $filename do not include (according the Documentation) fields like the --post_name,--post_date among others "post"s fields, thus requiring a following wp post update $id_media for setting them.

Hence, it is not possible to wp media import $filename to overwrite a Media image with a given --post_name -WP actually just create a duplicated media object, with a new regenerated post_name-, thus all the wp post exist and wp post delete process must be done "manually".

Am I true with these observations?

Overwrite media matching post title using WP CLI's media import command

I am trying to overwrite a media post using the WordPress CLI.

The wp post create --post_type=attachment command can create an empty media item, but cannot attach an image file through WP-CLI. This is only possible through the GUI or other WP PHP Functions. The CLI command creates a "corrupt" media post. Is it better to avoid using this method?

On the other hand, the wp media import $filename command does not include (according the Documentation) fields like --post_name,--post_date and other post fields. This method then requires running wp post update $id_media for setting these fields once the post is created.

Hence, it is not possible for wp media import $filename to overwrite a Media post that matches on --post_name. If you try this, WP actually just creates a duplicate media object, with a new regenerated --post_name. This means the wp post exist and wp post delete process must be done manually as a part of this process.

Is my thinking correct?

deleted 17 characters in body
Link
Brethlosze
  • 149
  • 1
  • 2
  • 11

Post Create Attachment vs Media Import with a given Name

deleted 17 characters in body
Source Link
Brethlosze
  • 149
  • 1
  • 2
  • 11

The wp post create --post_type=attachment command can create an empty media, unable to be filled with an image through WP-CLI, only through the GUI or other WP PHP Functions (thus creating a "corrupt", better-to-avoid use from a WP-CLI user?)

By other side, the wp media import $filename do not allowinclude (according the Documentation) itsfields like the --post_name,--post_date among others "post"s parameters to be setfields, thus requiring a following wp post update $id_media, for setting the --post_name,--post_date among othersthem.

Hence, it is not possible to wp media import $filename to overwrite a Media image with a given --post_name is already taken (-WP actually just create a duplicated media object, with a new regenerated post_name)-, thus all the wp post exist and wp post delete process must be done "manually".

Am I true with these observations?

The wp post create --post_type=attachment command can create an empty media, unable to be filled with an image through WP-CLI, only through the GUI or other WP PHP Functions (thus creating a "corrupt", better-to-avoid use from a WP-CLI user?)

By other side, the wp media import $filename do not allow (according the Documentation) its "post"s parameters to be set, requiring a following wp post update $id_media, for setting the --post_name,--post_date among others.

Hence, it is not possible to wp media import $filename to overwrite a Media image with a given --post_name is already taken (WP actually just create a duplicated media object, with a new regenerated post_name), thus all the wp post exist and wp post delete process must be done "manually".

Am I true with these observations?

The wp post create --post_type=attachment command can create an empty media, unable to be filled with an image through WP-CLI, only through the GUI or other WP PHP Functions (thus creating a "corrupt", better-to-avoid use from a WP-CLI user?)

By other side, the wp media import $filename do not include (according the Documentation) fields like the --post_name,--post_date among others "post"s fields, thus requiring a following wp post update $id_media for setting them.

Hence, it is not possible to wp media import $filename to overwrite a Media image with a given --post_name -WP actually just create a duplicated media object, with a new regenerated post_name-, thus all the wp post exist and wp post delete process must be done "manually".

Am I true with these observations?

added 4 characters in body
Source Link
Brethlosze
  • 149
  • 1
  • 2
  • 11
Loading
added 4 characters in body
Source Link
Brethlosze
  • 149
  • 1
  • 2
  • 11
Loading
added 102 characters in body
Source Link
Brethlosze
  • 149
  • 1
  • 2
  • 11
Loading
Source Link
Brethlosze
  • 149
  • 1
  • 2
  • 11
Loading