Articles of json

Is it possible to pass variables to WordPress externally?

I would like to know if it is possible to pass json variables from a form which is located outside WordPress? This is the situation: The user fills a form located on x server. Then his answers are sent to the WordPress site located in Y server in which depending upon his answer he will […]

Call Ajax URL in Plugin

Plugin Class File: function __construct() { add_shortcode(‘user_registration_form’, array($this, ‘shortcode’)); } public function hook(){ add_action( ‘wp_ajax_get_product_serial_callback’, ‘get_product_serial_callback’ ); add_action( ‘wp_ajax_nopriv_get_product_serial_callback’, ‘get_product_serial_callback’ ); } public function product_serial_ajax() { ?> <script type=”text/javascript”> jQuery(document).ready(function(){ alert(‘Hello World!’); jQuery.ajax({ type: ‘GET’, url: “<?php echo admin_url(‘admin-ajax.php’); ?>”, //url: ajaxurl, dataType : “JSON”, data : {action: “get_product_serial_callback”}, //cache: false, success: function(data){ alert(‘Eureka’)’; } […]

Retrieve list of taxonomies in json

I have custom taxonomies like that /wp-admin/edit-tags.php?taxonomy=my_cat&post_type=my_poet I want retrieve list of taxonomies in json add_action(‘init’, array($this, ‘json_handler’)); I tried function json_handler(){ $categories = get_terms( ‘my_cat’, ‘orderby=count&hide_empty=0’ ); print_r($categories); } Outpot WP_Error Object ( [errors:WP_Error:private] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy ) ) [error_data:WP_Error:private] => Array ( ) ) But […]

Can't add classes using jQuery from a JSON string with get_body_class()

In order to refresh the classes on the <body>element after an AJAX call, I am writing at the top of my AJAX response the following in JSON: $o[ ‘classes’ ] = get_body_class(‘project’); I can then see in the JSON response the following: “classes”:[“single”,”single-project” ,”postid-1793″,”logged-in”,”project”,”default”] What I am trying to do is to put all those […]

Changing order of db results when encoding to JSON

There is probably a very simple solution to this but I just can’t work it out. I am getting some info from the wp database, bypassing WP’s built in classes, then echoing the results as encoded JSON data like this : $db = new PDO(‘mysql:host=localhost;dbname=dbname’, ‘dbusername’, ‘dbpassword’); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = ‘SELECT user_login AS name, […]

Jetpack JSON API configure button not showing

Installed fresh WP on my Hostgator – shared host plan. Installed Jetpack, connected to wordpress but can’t make the JSON API to work. After activating there’s no Configure button just deactivate button and i’m stuck. Thank you

Plugin Development: Storing and Manipulating Data That Fits JSON in Database

I am new to WordPress plugin development but not web development in general. I have a website whose functionality I am trying to port over to WordPress for a client that needs it in a custom plugin and theme. On my other (non-Wordpress) website, which is a shop page, I have no way of editing […]

WP Rest API and json_decode()

I’m getting familiar with the WP REST API 2 plugin and I started following the amazing directions from Torque’s Guide. Everything seems pretty clear but I’m having trouble understanding this error (Keep in mind I’ve follow and reviewed all directions step by step. Here is the function I’m using: $url = ‘http://rbm.dev/wp-json/wp/v2/works/53’; $response = wp_remote_get( […]

Strip comma from last element in concatenated JSON string

I’m using Advanced Custom Fields plugin to generate schema data in json-ld format. I’m using the repeater for breadcrumbs and it’s working wonderfully, however to get valid markup I need to remove the comma from the last repeater/breadcrumb item. Here’s my code: <?php if( have_rows(‘breadcrumb’) ): ?> <script type=”application/ld+json”> { “@context”: “http://schema.org”, “@type”: “BreadcrumbList”, “itemListElement”: […]

Redirects based on a JSON file

Having a JSON file, how can we set up WordPress to redirect the urls (if it’s found in the JSON file)? For example: { “foo”: “bar”, “foo-1”: “baz” } Then /foo will redirect to /bar and /foo-1 to /baz. What’s the best way to do this? Currently I do it with rewrite_rule in functions.php, but […]