Editing Terms & Term Meta with the WordPress REST API

Here are some JavaScript snippets to manipulate WP_Term objects in WordPress using the REST API and the Backbone JavaScript client library. Insert a term Delete a term This next example assumes you’ve used wp_localize_script() to make the REST API endpoint and a nonce available in an object myplugin. If you need help doing this, please… Continue reading Editing Terms & Term Meta with the WordPress REST API

Published
Categorized as WordPress

Disable tooltips on The Events Calendar month view

Here is a file you could save in wp-content/your-theme/tribe-events/month/content.php that will disable tooltips on the month view calendar produced by The Events Calendar plugin. This is a template override for the month view that adds a few lines of JavaScript to remove some event handlers, and it removes a call loading the tooltip template. The… Continue reading Disable tooltips on The Events Calendar month view

Published
Categorized as WordPress

What is $posted_data passed to Contact Form 7’s wpcf7_posted_data hook

For a ContactForm7 form that has this source: <div class=”wpcf7-lead-widget”>[text* contact-name maxlength:50 placeholder “Your Name (required)”] [email* email maxlength:50 placeholder “Email (required)”] [text phone maxlength:15 placeholder “Phone”] [vehicle_form_field] [textarea comments x3 placeholder “Questions and Comments”] [submit class:_button class:_button-small “Check Availability”] [hidden context id:context “contact”] [hidden do-not-send-mail]</div> The $posted_data that is passed via the wpcf7_posted_data hook… Continue reading What is $posted_data passed to Contact Form 7’s wpcf7_posted_data hook

Published
Categorized as WordPress

Migrating a GravityView Without Losing Fields

Exporting a GravityView and importing it into a different site is easy, and there are official instructions right here. This process works very smoothly when the Gravity Forms and GravityViews on both sites are identical. That’s usually not the world I live in, however. I’m a back-end developer in sites that sometimes have multiple teams… Continue reading Migrating a GravityView Without Losing Fields

Published
Categorized as WordPress

Sometimes, an array is passed to the get_callback provided to register_rest_field() instead of an object

When using register_rest_field() to add fields to terms in the WordPress REST API, the $object sent to your get_callback function will be an array instead of an object like the documentation describes. An object will still be passed, sometimes, too. Here is an example of how I work around this problem: function add_api_term_fields() { //location-phone-hours… Continue reading Sometimes, an array is passed to the get_callback provided to register_rest_field() instead of an object

Published
Categorized as WordPress

WordPress REST API returns 500 error when updating serialized meta with an unchanged value

Take care when updating posts via the WordPress REST API to not send unchanged serialized meta values. The entire update will fail and return a 500 error. The JSON response looks like this: { “code”: “rest_meta_database_error”, “message”: “Could not update meta value in database.”, “data”: { “key”: “meta_key_name”, “status”: 500 } } This error comes… Continue reading WordPress REST API returns 500 error when updating serialized meta with an unchanged value

Published
Categorized as WordPress

Setting post_parent with the WordPress REST API

WordPress 4.9.4 does not support the post_parent attribute in the REST API, so I wrote a plugin that does. Download here: https://github.com/csalzano/wp-api-add-post-parent Someday, WordPress core will allow the manipulation of the post_parent attribute, and I look forward to deleting this plugin and this blog post when they become obsolete. Until then, I believe this implementation resembles… Continue reading Setting post_parent with the WordPress REST API

Published
Categorized as WordPress

Spinners and loading animations built into WooCommerce

WooCommerce is a big plugin that ships with several JavaScript loading animations. There is no reason to roll your own when you need one. This week, I am hacking on WooCommerce to convert “Add to Cart” buttons to prevent redirecting users to different pages. Here’s a great tutorial I used to accomplish this goal. Without… Continue reading Spinners and loading animations built into WooCommerce

Published
Categorized as WordPress