bishless.com

Daniel Bishop mumbles in hypertext

Page 2 of 16

Leathering – week 1

I picked up a nice brown leather case (Apple | Amazon) for my new phone earlier this week. I figured it could be fun to track how it wears over time. So…

Maybe after a year I’ll compile them into a time lapse or something?

School’s Out For Summer!

I worked from home today since the kids are now out of school and the wife still had to work.

At some point mid-day, I got the inkling to go work outside on the patio since it wasn’t as hot as it has been. Sure, it’s summer in Arizona… but I’ve lived here most of my life. I could handle a little heat.

I made it 3 minutes before coming back inside.

Setting custom field values on old WordPress posts in bulk via WP-CLI

If you are a WordPress user that takes advantage of custom fields and WP-CLI… this may interest you.

Let’s say you’re using ACF field groups on posts in a certain category. You have a new custom field with a default value you’ve added to that field group. You’ve already modified the template to conditionally show a piece of UI based on that field value. Finally, you realize that now you’re going to have to open each post in the editor, one at a time, to save it in order to get that field value set.

Or… maybe there’s a way to script it?

In my situation, I only have about ten posts that need this treatment, but if I was looking at manually updating each post to include that new default value across hundreds of posts… /shudder

I decided to research & teach myself the steps I’d need to work through if I ever find myself in that situation.

Where are ACF values set in the database?

ACF field values are stored in the wp_postmeta table.

custom fields in wp_postmeta

There are actually two rows in post_meta. One is the actual value. The other is a reference.

Test: Update one post via WP-CLI

We’re going to try using wp post update1.

wp post update 4045 --kjzz_has_audio=1 --_kjzz_has_audio=field_59038b5c9457b

Successfully updating meta on a specified post

Ok, that’s a good start.

How can we affect only posts in X category?

Thankfully, in my situation, all the posts I need to affect belong to a specific category. I can grab a list of the post IDs with this:

wp post list --category_name=category-slug --format=ids

The whole command

So, now I need to combine the two.

Like most situations in life, I can’t be the first person to be in this boat. Someone has to have written about this in the past, right?

After a little searching, I ran across Updating Multiple Posts’ Meta | Mika Epstein. Check out Mike Little’s suggestion in the comments… That looks promising!

And this is what I ended up with:

for id in $(wp post list --category_name=arizona-business --fields=ID --format=ids); do wp post update $id --kjzz_has_audio=1 --_kjzz_has_audio=field_59038b5c9457b; done

BAM!

Successfully updating meta on a specified post

Victory Almost.

After inspecting a few of the records in Sequel Pro, it looked like the ones that already had those custom fields were ‘updated’ (to the same value), but the ones that didn’t have those custom fields yet did not actually get new meta added.

Looks like we’re actually going to need wp post meta and we’ll need to update/add each meta key/value individually.

Victory!

for id in $(wp post list --category_name=arizona-business --fields=ID --format=ids); do wp post meta update $id kjzz_has_audio 1; done

then…

for id in $(wp post list --category_name=arizona-business --fields=ID --format=ids); do wp post meta update $id _kjzz_has_audio field_59038b5c9457b; done

BAM!


… Now I’m wondering if I could have used:

for id in $(wp post list --category_name=arizona-business --fields=ID --format=ids); do wp post meta update $id kjzz_has_audio 1 && wp post meta update $id _kjzz_has_audio field_59038b5c9457b; done

  1. Nope. Close… but that doesn’t add the custom fields if they’re not there ↩︎

Bumpr

I use a lot of browsers throughout the day.

screenshot of several browser icons in a Launchpad folder on macOS

Up until a couple days ago, that meant when testing specific things, I had to right-click a link, copy the url, then paste into the browser I wanted to test in.

With Bumpr installed and set as my default browser, it intercepts links I click and pops up a quick menu of my installed browsers[^ or a subset of them… you can configure which are available] for me to quickly choose from. It’s a tiny interruption in my normal browsing around, but it’s so worth it for the convenience it offers.

But it doesn’t stop there… it provides the same functionality with email apps. Say you have the native Mail.app configured with your work email account and some other app like Spark or Airmail setup w/ your personal account. Click on a mailto link and Bumpr will ask you which email app you’d like to use to compose and send your message.

Bumpr's UI for choosing a mail client after clicking a mailto link

TIL iA Writer can copy markdown and paste HTML

At my day job, I get a lot of web content that starts out in email messages or Word documents.

Sometimes it’s even spread across both.

Jon Stewart crumples papers angrily

I’m kinda glad I don’t know how many times I’ve copied that content, reassembled it, and manually massaged the HTML in WordPress1. This process isn’t hard but takes a few steps and I’ve always fantasized about automating it somehow.

In fact, earlier this morning, I received an unordered list of topics for an upcoming seminar. I copied the text from an email into iA Writer and added the dashes to each line to make it a Markdown list. I then exported that file as HTML, popped it open in Sublime Text 3 to copy the well-formed markup and paste it into WordPress. It got the job done but was still more steps than I’d like.

Someday… I’ll get something quicker figured out.

iA Writer vs. Bear

Lately, I’ve been torn between iA Writer and Bear apps. I love the simplicity of writing in Markdown and with either app, I have access to my all my notes across phone, tablet, and laptop. I keep going back and forth trying different features in each app attempting to get myself to commit to one.

I was doing a little research this afternoon and stumbled across Matthew Temple’s article comparing Ulysses and iA Writer

“… both let you write in Markdown, copy as HTML, export as …”

[doubletake]

Wait! Copy as HTML?

I’ve gotta try this.

Victory

Sure enough. I opened that quick note from earlier w/ the markdown list, selected the text, and found Copy HTML in the menu. No exporting another file to open and copy from.

Here’s the before and after.

iA Writer - Copy as HTML result

OMG! I’ve been wasting so much time!

iA Writer vs Bear

I’m still futzing around w/ both apps; really like them both. I’ll update this post if I ever settle on one long-term.


  1. turn off the Visual Editor or die ↩︎

Fickle Dev

I’m a loyal husband.

When it comes to software… I’m apparently quite fickle.

I seem to cyclically rotate from Chrome > Firefox > Safari > Opera (and some of their developer/preview versions) as my default browser every couple months. I also tend to do the same with code editors like Sublime Text, Visual Studio Code, Atom, and others. Looking back, I’ve done it with WordPress, Ghost, and some other CMSes over the years.

Freedom to switch is a powerful thing. But I’d really be a fan of myself if I’d jot down a note in some consistent place about why I’m switching.

Someone build Switch Log or Fickle Logic or whatever you think it should be called.

Arizona sunsets never get old

(Forgive the Culver’s drive-thru sign. ;))

Instagram #2016bestnine

Looks about right: family in the center… with lots of board games. 🙂

Circle with Disney – A Dad’s Review

Have you ever wondered just how much time you’ve accidentally sunk into Instagram or Facebook in one day? Or how much time your kids have actually been playing Minecraft or watching Youtube videos?

Our family found a little white box that can reveal that information and let you take control of it for better balance in your household.

Circle with Disney

Continue reading

Top 5 Christmas Songs in Daniel Bishop’s earholes

  1. O Come O Come Emmanuel – August Burns Red
  2. O Holy Night – Becoming the Archetype
  3. God Rest Ye Merry Gentlemen – Fit for a King
  4. Little Drummer Boy – August Burns Red
  5. Silent Night – Forevermore

So good!

« Older posts Newer posts »

© 2018 bishless.com

Theme by Anders NorenUp ↑