Posts

Querying WordPress Multisite Sites With Meta Queries

WordPress documentation is usually robust. However, recently I had a use case where I needed to query sites by custom meta values. In WordPress 5.1, the WP_Site_Query was introduced to allow a faster way to query sites in a WordPress Multisite setup without using the old hack of needing to get all ID values using get_sites and then inside of a loop using switch_to_blog to query the sites and get values.

Get Advanced Custom Field Options by Site ID in WordPress Multisite

Out of the box, Advanced Custom Fields offers immense power but provides no functions to work with WordPress Multisite sites. Fortunately, WordPress makes it easy to work with multisite sites. Throw the following function into your theme functions.php file and call it at will. Just provide the field name and site ID, the function will get your value from that site (if there is a value and field exists). function get\_acf\_site\_option($field\_name, $site\_id) { switch\_to\_blog($site\_id); $value = get\_field($field\_name, 'option'); restore\_current\_blog(); return $value ? $value : null; }

The Most Efficient Way to Bulk Delete Things in WordPress

What is the most efficient way to delete thousands of posts, custom post types, media attachments and other things in WordPress? The answer is: not through the admin panel. If you have ever tried deleting a couple of hundred (or so) items from the WordPress admin panel before, then you would know if the request doesn’t timeout, you’ve won the WordPress lottery. And, if it does timeout, you have to keep spamming the refresh button until it works.

My Experience Writing a Long-Running PHP Script to Parse News Content From the Associated Press News API

Filed under: super-specific use case with hints of generality for those wanting to write long-running PHP scripts. For a little while now, I have been building a site with WordPress that consumes news content from the Associated Press news API and then stores the news content in WordPress. My first iteration of the ingest engine with PHP worked quite well, but I encountered dreaded NGINX server timeouts and other issues.

How to Work With DATETIME Values in JavaScript

Dates in Javascript have always been a PITA. It is one of the reasons that libraries like MomentJS reigned supreme for so long. Things are complicated, especially if you’re dealing with different timezones. Fortunately, working with simple DATETIME values has never really been a problem. What prompted this post was that I am working with WordPress a lot at the moment, and all dates in WordPress are MySQL DATETIME formatted dates. Say you have a DATETIME value that looks like this: 2021-10-05 00:00:00 — you can use the Javascript Date object on this because it’s a valid date value.

The Whole of Twitch (and a bunch of other affiliated sites) Has Been Leaked

If you thought the CD Projekt Red leak of Cyberpunk 2077 and other source code was bad, get a load of this latest leak. Twitch just got hacked entirely, and the entirety of its source code, internal repositories, financial payout information and absolutely everything you can think of has been taken and put online in a 128GB torrent over on 4chan. The anonymous individual or group says, “we have completely pwned them,” and let’s be honest, they’ve well and truly pwned Twitch here. What a massive leak. Some heads are going to roll over in the IT department over this. I am curious how this even happened.

A Quick Review of Windows 11: Should You Upgrade?

If Windows 11 were a product with a slogan, it would be “same Windows, now 50% less ugly.” With Windows 11 finally, upon us, the question on the lips of many is: is it worth the upgrade? Instead of starting from scratch, Microsoft took Windows 10 (which was already quite good), pulled some levers, put some finesse on the UI and modernised a few parts of the 35-year-old operating system (which was starting to show its age).

How to Add Infinite Scrolling to a HTML Element With Vanilla JavaScript

There is a Javascript library for almost anything. But sometimes, it’s good to code your solutions to specific problems where the resulting code will be lighter, and you will feel more rewarded as a result. When it comes to infinite scrolling in Javascript, many examples, you will find online relate to scrolling the main window (which is a common thing). But what if you have an overflowing DIV that you want to add infinite scrolling on? The logic is the same.

How to Upgrade to Windows 11 if You Don’t Want to Wait for the Upgrade Prompt

Windows 11 is finally here, and like Windows 10, it will be a free upgrade for Windows 10 users. However, the rollout will be slow and staggered despite Windows 11 releasing on October 5, 2021. This means for many Windows 10 users. It could take months and upwards of mid-2022 before you get the upgrade popup (if your machine is compatible). If you are like me and live on the edge, you are most likely looking to upgrade now. The good news, you don’t have to wait for Microsoft to tell you that you can get Windows 11. There is a trick that currently allows you to upgrade without having to wait.

The Only Long-Term Casualties of the Pandemic Are Companies Who Push for Workers to Return to the Office

Some of you already know my stance on remote work vs the office. As the pandemic rages on, the world is trying to return to a sense of normality. Name a company that went out of business because its employees had to work remotely. Productivity of employees can be measured in output, not bums in seats in an office. As you’ll soon learn, remote work is no longer a Silicon Valley startup perk to attract talent. It’s now expected by many.