Ben Lobaugh Online

I think, therefore I am. I am, therefore I sail

Run a wp-cli command across the network

Need to run a wp-cli command across a network of WordPress sites?

Here is an example of how to add/update an option on every site on the network using wp-cli.

wp site list --field=url | xargs -n1 -I % wp --url=% option update my_option my_value

This is really two commands in one. Lets break them down:

wp site list --field=url

This command will get a list of all the sites on the network. The output is a list of the urls for the given site. Passing the url to a command on a network chooses the site to run the command on.

xargs -n1 -I % wp --url=% option update my_option my_value

Here is the kicker. This command takes the output of the previous command into xargs. Xargs then run the new wp command with each site’s url in it.

Using wget to crawl your website

If you are looking to crawl your website for something like cache warming you can do so with wget quite easily.

The following wget command will crawl a site and leave nothing behind on the local filesystem afterward.

wget --mirror -q -e robots=off -p -r --delete-after -nd http://www.isleofmtv.com
–mirror crawls the entire site
-q prevents wget from writing output to the buffer
-e robots=off ignores directives in robots.txt
-p get all page assets
-r recursively request pages
–delete-after clean up any local files after running wget
-nd prevents wget from writing a directory structure that gets left behind

New Toy: 2003 Jeep Grand Cherokee

Find and update WordPress posts with comments older than NNN days

I have a use case where I need to disable comments on posts in WordPress where the last comment was more than one year, or 365 days, ago.

Posts can be found with this query:

SELECT p.ID, p.post_title, p.post_date, p.comment_status, p.`ping_status`
FROM wp_posts AS p
WHERE p.ID IN (
     SELECT c.comment_post_ID
     FROM wp_comments AS c
     WHERE DATEDIFF( curdate(), c.comment_date ) <= 365
  );

The outer query takes the inner query as the search parameter. The inner query is finding the latest comment for each post based on the number in the WHERE condition. 365 represents 365 days, or 1 year.

Therefore, this query is getting the latest comment for post where the comment is less than 1 year old.

Now let’s say you need to update the posts to disable comments. The goal is to disable commenting for all posts that have not had a comment within the last year. It can be accomplished with the following:

UPDATE wp_posts
SET comment_status='closed', ping_status='closed'
WHERE ID IN (
		SELECT c.comment_post_ID
		FROM wp_comments AS c
		WHERE DATEDIFF( curdate(), c.comment_date ) >= 365
);

Here again the number 365 represents the number of days.

Check the posts and you should see the comments have been closed.

What I have been up to Q1 2018

People are noticing!
Noticing that I have not posted on this site in a couple months.

Yes I am still around! Kicking butt and taking names.
I have been working hard to make my 2018 Vision be, and continue to be, a reality.

How’s it going so far? Nailing It!

Lets go through the four vision statements…

Vision: Become a topnotch, well respected communicator and coach

To date I have completed/am currently doing:

Speaking Engagements 2
Masterminds 3
Coaching Coaching: 27 sessions with 6 clients for 41+ hours!

Just today in fact I spoke for Simply Beautiful Tiny Homes LLC during a Real Estate Investors Association of Washington training day on Team Building and Communication.

There is a lot more coming down the line too! For example, I currently have 528 mastermind sessions planned with clients. Some of those sessions are part of a year long daily growth session.

Vision: Let my money make me money, not me making money

This is my second most actively worked vision, after the next vision which involves my relationship with my wife.

To date I am actively working with startups (new businesses) in the following categories:

In planning phase 2
Pre-launch 1
Self-sustaining 2

Vision: Build an ever improving relationship with my wife that others coming behind can model after

This is the most exciting vision for results!

Alix and I have been growing together exponentially. The last two years have been very busy for us personally and combined. As you can see from above I have a lot going on, so does Alix. She is currently working as a NICU nurse, finishing a Masters in Nursing Education, and running her own clothing business.

At the beginning of the year we read the book How to Improve Your Marriage Without Talking About It. In the book, the authors share the differences between men and women and how we relate to our environment and each other. It walks the reader through the physiological and phycological differences between men and women and provides clear examples on how a situation affects each sex with proven scientific research. This book has opened our eyes to truly be able to see from the other persons perspective and quickly reestablish connection. I 100% believe every dating and married couple should read this book.  If you have not read it already please please please make it top on your list to get a copy and read it. I would love to hear how it changes your life. Drop me a message on the contact form and lets chat!

Vision: Live a slow paced life

Though it may not sound like it from the above I am actually accomplishing this vision too! Sure I have a lot on my plate but it is on my schedule. I have been using Pareto’s 80/20 Rule to analyze and aggressively cut out activities that fall into the 80% category. This has resulted in a much calmer, more peaceful state of being. It has allowed me to expend more time and dedicated energy in communing with Alix and close friends, as well as dialing in the areas of my life that move me towards my goals. As a bonus, I have been able to read again. I set a goal of 80 books this year and as of this writing have finished 18!

Life is good!
I expect it only to continue getting better!

Page 1 of 147

Powered by WordPress & Drip City Coffee