oneOf two possible objects in WP REST API?

Aight got it, the crucial missing thing was that you have to provide this part here: ‘type’ => ‘object’ twice; once when declaring the variable’s type, and once again when defining the possibilities. Otherwise, validation fails; so a proper example would be: ‘args’ => [ ‘data’ => [ ‘type’ => ‘object’, ‘oneOf’ => [ [ …

Read more

Force array to be a string [closed]

There are a few ways you can make an integer a string. Here are 2 main ways to make that happen Type Cast – $values_x[] = (string) $series[0][‘data’][$i][0] Double Quote – $values_x[] “{$series[0][‘data’][$i][0]}” Also, you might want to check for null first and assign a default $values_x = !empty($values_x) ? $values_x : array(‘2010’); If you …

Read more

How can I json_encode the output of my function?

Not sure if the get_all_images() function is the one that is added to your wp_ajax_{action} hook. If it is you will want to output a string back to your js. I would define a variable and concatenate the img html to it as you loop through your images. function get_all_images() { //your code $response=””; foreach($images …

Read more

Store images and videos category wise and fetch them in json format

Some how able to get all the images from media library. This is very close. $query_images_args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => – 1, ); $query_images = new WP_Query( $query_images_args ); $images = array(); foreach ( $query_images->posts as $image ) { $images[] = wp_get_attachment_url( $image->ID ); }

JSON Object Value Show Undefine

You either need to tell jQuery that you expect a json response from the server: $(“#txt-cmt”).keypress(function(e) { if (e.which == 13) { var comment = $(this).val(); var message = { action: ‘show_comment’, user_message: comment }; $.post(ajaxUrl.url, message, function(data) { console.log(data.user_name); }, ‘json’); } }); or you need to parse the response as json with JSON.parse().

Custom Backend data for map to JSON file?

Use the JSON REST API – http://v2.wp-api.org – It lives as a plugin now but will eventually be part of WP Core – https://wordpress.org/plugins/rest-api/ To manually output JSON, use a combination of wp-ajax to handle requests and wp_json_encode() / wp_send_json_success for simple PHP Objects and Arrays. See https://codex.wordpress.org/AJAX_in_Plugins

How do i save this python code to text file.? [closed]

It’s off-topic but if you just want to write the setup and punchline values to a text file you can do something like this: # Dependencies import json import requests # Specify the URL url = “https://official-joke-api.appspot.com/jokes/programming/ten” # Make request and store response r = requests.get(url) print(“Status code:”, r.status_code) jokes = json.loads(r.text) with open(“outfile.txt”, “w”) …

Read more

I am unable to fetch json data from wp_db

$user1 = $wpdb->get_results(“SELECT * FROM diary_user_form_storage”); foreach ($user1 as $key => $value) { $productString = stripslashes($value->product); $product=json_decode($productString,true); $error_p = implode(‘ ‘, $product[0]); echo $error_p; } Out will be PRODUCT 2 PRODUCT 5

Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)

In general, this function lets you localize your JS strings, but you can also use it to set global JS variables: function set_my_js_var() { // logic here for returning the right JS var $myVar = “Hello World”; return $myVar; } function load_fe_scripts() { wp_enqueue_script( ‘global-js-var’, get_template_directory_uri() . ‘/js/my_file.js’ ); $localize_array = array( ‘my_js_var’ => set_my_js_var() …

Read more