Limit get_terms to Posts in Query

Every now and then we need to create a list of taxonomies that are not just empty, but are also not found in the posts for that page.

I recently found a pretty sweet solution over on Stack Overflow and wanted to share.


Get Post IDs using array_column()

We often have to do queries for post IDs which we then use for a later query. However, I don’t think WordPress has a way to return just the result set we want which is a one dimensional array of post_ids. Instead it returns an array of objects (or arrays) with a post_id property. One way to get those post_ids into their own one dimensional array is to loop through your results and pick them out one by one…boring.

If you run into a similar problem try using array_columns to automagically pull a one dimensional array of post_ids out of a two dimensional array.


Regenerate Woocommerce Download Permissions

We recently imported a large number of orders and files from and older legacy / custom Ecommerce site into a Woocommerce site.

There are a lot of tales to tell in this adventure, but a big one was getting all of these files attached correctly to the product variations downloadable file.

It took a while to find a good solution, but thankfully Chris Hawkins had a good answer for me over on Stack Overflow.

Here is essentially what my solution looked like:

This only needs to be run once for each order so this can be run from almost anywhere. Make sure to update your offset until you make it through all your orders AND that you already have all your files in place.

That is it! I hope this helps someone!

Woocommerce Custom Endpoint

Sometimes we need to add a new account menu item for Woocommerce. If you have the same problem the code below should get you 90% of the way there. Just need to build out your own template part.


Google Autofill Covers Address Autocomplete

I have run into this a few times and it always bothers me. Google has an auto fill function for forms that is sometimes really handy as a user, but sometimes breaks ui elements if you are a dev.

This is especially bad with the Google Address search because it seems to reset your autofill / autocomplete attributes each time you focus on the element.

If you are running into this issue here is a good thread with a couple good solutions for hiding the autofill.

The jQuery solution is what I found worked best for myself.


JS Highlight Text

I needed to setup some text search functionality on a page and the client really wanted the searched words to be highlighted.

I found a great library for exactly this over on The Art of the Web.

They do a great job of explaining this library so please check them out to learn more!