# Installing WP-CLI in Windows (ok)

Sử dụng: [https://wp-cli.org](https://wp-cli.org/)

Chú ý:&#x20;

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2FOlE8FzQRjBhTWb676nOp%2Fimage.png?alt=media&#x26;token=a05a2a61-6e11-4dc0-814c-a61fe2580214" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2F7bd4KWWUpWJD5kX3mXFf%2Fimage.png?alt=media&#x26;token=6f0a2f47-7cc0-47f4-8369-0fcdbea0f1cd" alt=""><figcaption></figcaption></figure>

## Đây cách này hay dùng (nó tạo ra 1 file upload duy nhất)

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2F8bICswqO0iNkT2NosHcZ%2Fimage.png?alt=media&#x26;token=d4d0a4c5-1edb-4877-9cc5-1da13b86b672" alt=""><figcaption><p>wp media regenerate --yes &#x26;&#x26; $default_sizes = [];</p></figcaption></figure>

Ta thấy nó tạo duy nhất 1 link

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2F4UPQEOwXqvT1W3fsPZC1%2Fimage.png?alt=media&#x26;token=db4a011e-b10b-47fe-b370-c23df04984e7" alt=""><figcaption></figcaption></figure>

Kể cả shop cũng vậy

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2F0ybq4SHRP27wGO8nS2P8%2Fimage.png?alt=media&#x26;token=df23756b-7b51-46e6-a3c0-96b76d1d59a3" alt=""><figcaption></figcaption></figure>

Trong back-end cũng hiển thị 1 ảnh chỗ thumbnail

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2F04Xeyql7DrkSjO3sI4NO%2Fimage.png?alt=media&#x26;token=e276f164-a3f7-452f-9081-23032fd27a07" alt=""><figcaption></figcaption></figure>

Rồi ta tắt đi và thực hiện lại nó lại hoạt động

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2FpU2MhUuD6MD6IQR8wDeB%2Fimage.png?alt=media&#x26;token=a772ba8e-ca78-4157-a9f8-61c51722ebcb" alt=""><figcaption></figcaption></figure>

Đôi khi nó hoạt động như điên ta chỉ cần tắt trong functions.php nó hoạt động không như lúc trước ta cần phải vào media.php cần chú ý

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2Fj3fa5JvKE6Jr8l6OWZUX%2Fimage.png?alt=media&#x26;token=cf9830f2-f516-42c6-8989-564a15487f67" alt=""><figcaption></figcaption></figure>

Ta thử up  1 ảnh xem sao nó đúng là chỉ tạo 1 ảnh

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2FhBuriPQyHigYDOxH1ikk%2Fimage.png?alt=media&#x26;token=11c1e5bf-7a16-4d94-bffa-09e23165bfbf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2F6ZLz69mc78MQmYBfFlUv%2Fimage.png?alt=media&#x26;token=7804f4fa-a9ea-4123-a64b-9216d86cb2c4" alt=""><figcaption></figcaption></figure>

Hiện tại không hiểu sao nó chỉ chạy cách 2

<figure><img src="https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2FQUsDYUdGPtf0GBnD4trB%2Fimage.png?alt=media&#x26;token=9f841c29-7806-4c43-a243-5574dde7405d" alt=""><figcaption></figcaption></figure>

### Cách 1: dùng 1 lệnh `composer global require wp-cli/wp-cli`

If you're seeing "zsh: command not found: wp" when trying to use WP-CLI in your site shell, it means that the WP-CLI tool isn't installed or properly configured on your system, and you need to install it before you can use its commands within your site shell. How to Fix:

* **Install WP-CLI:**
  * **Using Composer:**
    * Open your terminal and navigate to your WordPress root directory.
    * Run the command: `composer global require wp-cli/wp-cli`
  * **Manually (on Linux/macOS):**
    * Download the latest WP-CLI package from the official website.
    * Extract the archive and place the `wp` executable file in a directory within your system path (e.g., `/usr/local/bin`).&#x20;

Things to Check:

* **Path Variable:**
  * Ensure that the directory containing the `wp` executable is added to your system's `PATH` environment variable.
  * You can check this by running `echo $PATH` in your terminal.
* **Site Shell Access:**
  * Verify that your site shell is properly configured to access the correct WordPress directory on your server where WP-CLI should be available.
* **Permissions:**
  * Make sure you have the necessary permissions to execute the `wp` command.&#x20;

Troubleshooting Steps:

* **Check Installation:**
  * Try running `wp --version` in your terminal. If it returns information about the WP-CLI version, it's installed correctly.
* **Re-source Environment:**
  * If you recently installed WP-CLI, try re-sourcing your shell configuration file (e.g., `.bash_profile` or `.zshrc`) to update your environment variables.
* **Specific Environment Issues:**
  * **Local Development:** If you're using a local development environment like Local by Flywheel, check their documentation for specific instructions on installing and using WP-CLI.&#x20;

### Cách 2: Cài bằng cách tải file về.

{% file src="<https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWPtKFbhw0XehxVuoiZ%2Fuploads%2FUqGc6lvEUXZfmz4eCcHM%2Fwp-cli.phar?alt=media&token=ec9a1903-fe40-4360-948a-d62b9101602e>" %}

C:\wp-cli\wp.bat

```
@ECHO OFF
php "C:/wp-cli/wp-cli.phar" %*
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOU86p0bJk38zmOcR3e%2F-MOU9Rm4Md4cxVzN8hCK%2FScreenshot_1.png?alt=media\&token=0925c25d-a5f3-4c5f-a87a-60b232d8bf7d)

```
C:\wp-cli
C:\xampp\php
```

```
wp --info
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOU86p0bJk38zmOcR3e%2F-MOU9fGnMpZI1ShxfgyN%2FScreenshot_3.png?alt=media\&token=f75ce4b0-62ef-495a-b413-0b466f871432)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOU86p0bJk38zmOcR3e%2F-MOU9i6hAiBNxqBgijfl%2FScreenshot_2.png?alt=media\&token=31de174b-7c2b-447e-b714-ddc5382dfbb1)

Ví dụ:

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOUHdtzD9WfxZesJzVd%2F-MOUI8jYHrSFM_YYvd_N%2FScreenshot_4.png?alt=media\&token=d0bda4bf-21a5-4bd1-ad75-ea612c349048)

<https://developer.wordpress.org/cli/commands/plugin/install/>

```
wp plugin install bbpress --activate
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOUIBG7-CHFP0DCCdzj%2F-MOUIHO1SZ-QuMJRKOP7%2FScreenshot_5.png?alt=media\&token=e3da2e46-7485-4472-ac3f-619e4784b23b)

Cài đặt trên git

```
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
wp --info
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOUIUjn1MvWGNxLkMD7%2F-MOUJOp2qgDJEI02Mik3%2FScreenshot_6.png?alt=media\&token=99f1be69-d50b-4bfd-8cac-f90af151c643)

<https://developer.wordpress.org/cli/commands/post/create/>

## Config

{% embed url="<https://make.wordpress.org/cli/handbook/references/config/>" %}

C:\xampp\htdocs\example\wp-cli.yml

```
# Global parameter defaults
path: C:/xampp/htdocs/example
url: http://localhost/example
user: admin
color: false
disabled_commands:
  - db drop
  - plugin install
require:
  - path-to/command.php

# Subcommand defaults (e.g. `wp config create`)
config create:
    dbuser: root
    dbpass: 
    extra-php: |
        define( 'WP_DEBUG', true );
        define( 'WP_POST_REVISIONS', 50 );

# Aliases to other WordPress installs (e.g. `wp @staging rewrite flush`)
# An alias can include 'user', 'url', 'path', 'ssh', or 'http'
@staging:
    ssh: wpcli@staging.wp-cli.org
    user: wpcli
    path: /srv/www/staging.wp-cli.org
@production:
    ssh: wpcli@wp-cli.org:2222
    user: wpcli
    path: /srv/www/wp-cli.org

# Aliases can reference other aliases to create alias groups
# Alias groups can be nested
@both:
 - @staging
 - @production

# '_' is a special value denoting configuration options for this wp-cli.yml
_:
    # Merge subcommand defaults from the upstream config.yml, instead of overriding
    merge: true
    # Inherit configuration from an arbitrary YAML file
    inherit: prod.yml

```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOUL7uQLGVBv_r52CbF%2F-MOUMLzYjX-cYkEdAVd1%2FScreenshot_7.png?alt=media\&token=65f5a1ad-3840-46d2-bbef-b721ad3a0edc)

{% embed url="<https://developer.wordpress.org/cli/commands/post/create/>" %}

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOUL7uQLGVBv_r52CbF%2F-MOUMZ09xFDqJ8_QtYzi%2FScreenshot_8.png?alt=media\&token=970c6a62-25a1-4abc-a086-3842bb152bd4)

```
 wp post create --post_type=post --post_author='wordpress' --post_title='A future post' --post_status=future --post_date='2020-12-01 07:00:00'
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-MOUMaHw-H5wIJCYVGBu%2F-MOUNxFC0Y1f5lBLNYBM%2FScreenshot_9.png?alt=media\&token=1d7723ef-7d19-43a6-912c-49d5dea3ebbb)

## Quick Start&#x20;

<https://make.wordpress.org/cli/handbook/guides/quick-start/>

```
wp core download --path=wpclidemo.dev
```
