The functions below can be used to get a list of all Gravity Forms whose fields have a specific CSS class: View the code on Gist. Calling the first function looks like get_gravity_forms_with_css_class( ‘list-users2’ ) and the results it returns look like this: The keys of the array include the form ID and title. Each […]
If you have an indexed array of objects, and you want to remove duplicates by comparing a specific property in each object, a function like the remove_duplicate_models() one below can be used. View the code on Gist. The result is: View the code on Gist.
WordPress’ get_super_admins() function can be used to get the logins for all the users on the current site. Its return value is in array that looks like: [ ‘maryann123’, ‘johnsmith456’, ‘annie-mcarthur’ ]. If you want WP_User objects for each of those users though, you can use get_users() function and pass in get_super_admins() as the ‘login__in‘ argument, like this: View […]
The function below can be used for getting the WP_Term object for the term that’s currently being edited on the term.php page in the WordPress admin. Just make sure that when you call this, the global $taxnow variable has been set. Using WP’s admin_init hook, or anything that fires after that point will work. View the code […]
The following function can be used to get the absolute path to the WordPress uploads directory: View the code on Gist. It will return a path to where the WordPress /uploads/ directory is, whether it’s in the default location or whether an UPLOADS constant has been defined to specify an alternate location. The path it returns will look […]
The following function can be used to get the slugs of all fields in an Advanced Custom Fields flexible content field. By default, it returns the field slugs for the Flexible Content fields on the current page, but you can provide the optional $post_id argument to get the field slugs for any other post/page instead. View […]
I’ve seen posts and documentation online for how to get just the customer notes for an order, but no great ones for how to get all WooCommerce order notes. Here’s my solution for that: View the code on Gist. You just pass that function the order ID (post ID) for any order and it returns an […]
If somewhere in the code for a WordPress site there is a filter hooked to post_link that’s replacing the URL so that it no longer contains the %postname% placeholder, WordPress will assume there’s nothing to edit. It will therefore output the permalink on the post edit screen without the edit button next to it, and […]
Using the Gravity Forms + Custom Post Types WordPress plugin to map your Gravity-Forms-generated posts to a custom post type is very handy, but I noticed that it doesn’t seem to work with file uploads. This is because by default, Gravity Forms saves files to /wp-content/uploads/gravity_forms and stores their URLs. ACF on the other hand, saves files to the WP Media Library […]
If you want to get the file mime type for a remote file and you have its URL, the function below can be used. Example: If the remote file is a png image with a url of http://example.com/directory/image.png?ver=123, passing in that URL to this function would return image/png. View the code on Gist.
The get_the_excerpt() entry in the WordPress Codex says that it returns “…either a user-supplied excerpt, that is returned unchanged, or an automatically generated word-counted trimmed-down version of the full post content” (although the more up-to-date WordPress Developer Resources entry has no such language). I find that calling get_the_excerpt() doesn’t work when a post has post content but not a post excerpt. […]