How Can I setup WP CLI on Windows development machine running AMPPS?

Installing wp-cli through Composer is the way to go. For instance: $ cd C:\ $ composer create-project wp-cli/wp-cli –no-dev Copy the path to the bin directory inside the wp-cli directory (something along the lines of C:\wp-cli\bin) Add copied path to the Windows Path variable (tutorial) Exit all CMD’s (or git bash) and reopen them. Now … Read more

Can I create (or update) user password with WP-CLI by hash?

There is not “one command” in WordPress CLI that does the job: https://github.com/wp-cli/wp-cli/issues/2270 However using other commands, you can overide the user password directly in the database using the following: USER_ID=$(wp user list –login=”$USR_LOGIN” –format=ids) wp db query “UPDATE wp_users SET user_pass=”$HASHED_PASS” WHERE ID = $USER_ID;” First line is optional if you already know the … Read more

What’s the proper way to setup WP-CLI on Ubuntu so that I don’t have to use the flag –allow-root?

All files and folders should be owned by www-data user and group if not then WordPress can’t change files hence fails to update from dashboard. wp-cli says to use sudo -u www-data -i — wp <command> but that gives This account is currently not available. Why? See this answer: https://askubuntu.com/a/486661/695240 You’re getting the This account … Read more

Can wp-cli display all users and their roles across all sites in a multisite instance?

List all the admins of each site Side note: Dividing these up by site would also be handy. Let’s do that here: We can list the url of each site with: wp site list –field=url We can list all administrators of a given site with: wp user list –role=administrator –url=https://example.tld/site1 These commands can be combined … Read more

WPCLI search and replace variants for all tables

In a WordPress installation, a certain number of database tables are registered in the $wpdb object. To see what they are, you can run the WP-CLI command wp db tables. On my local WP installation, these are the $wpdb-registered tables: wp_users wp_usermeta wp_posts wp_comments wp_links wp_options wp_postmeta wp_terms wp_term_taxonomy wp_term_relationships wp_termmeta wp_commentmeta wp_blogs wp_signups wp_site … Read more

WordPress API – count posts

Assuming you are using Linux or OS X, the easiest way is probably to use wp-cli (if present in your WordPress installation) to return a list of all posts: wp-cli post list Then pipe it to the word count tool to get the number of lines: wc -l Finally, deduct one to take care of … Read more

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