Populating main menu from external JSON API

I would not bother creating a nav menu for this, I would just write a code that takes JSON as input and spits out menu markup with the data. WP’s menu data structures are quite unwieldy and aren’t too convenient to work with. There are also issues of persistence and performance (network request is usually … Read more

WordPress – Sync wordpress post with JSON feed

The important step is to assign a unique ID to every item you get from the source. Hopefully the JSON feed already includes one, but otherwise you will have to somehow create one yourself based on the JSON content. Once you have the value, you store it as a meta value of the post being … Read more

Base64 & JSON Encode array in PHP, use as HTML data attribute, decode and parse in JavaScript …. with proper Escaping

The possible output of base64_encode() contains a-zA-Z0-9+/ and possibly = or == appended. Testing with $str=”abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=”; we find that: esc_attr( $str ) === $str is true, so it looks like esc_attr() preserves base64 encoded strings. There are possible regexes to help with validation, but according to this answer by @BoltClock, we could check it with … Read more

CMB2 Repeatable Group & JSON API

Consider using the CMB2 API. <SITE_URL>/wp-json/cmb2/v1/boxes/<METABOX_ID>/fields/PhotoGalleryGroup?object_id=<POST_ID>&object_type=post You will need to enable the API feature for your box/fields. Documentation for that is in the wiki.

How to display Unicode correctly?

I’m not sure whether you are using a plugin, or you are coding it yourself. Either way, you can use server side or client side to decode or encode your content. PHP offers the utf8_decode(); and utf8_encode(); functions, that can be used to decode or encode your content before sending it to the browser, or … Read more

How can I get my options in json response?

You shouldn’t save your theme’s options one by one. In that case, you should call each of them separately, or store them in an array and then run a loop to get their values: $options = array( ‘option1’, ‘option2’, ‘option3’); foreach( $options as $option ){ // The rest of your code } But the proper … Read more

404 Error Contact Form 7 on WordPress

this is quite a common issue with htaccess file blocking malformed un-shlashed url such as cf7 wp-json requests. Therefore check your .htaccess file in your root folder to see if this is the case with your server too, find the section in your .htaccess that is adding a “https://wordpress.stackexchange.com/” at the end of requests # … Read more